check_active() with keyboards?
36 posts
• Page 2 of 4 • 1, 2, 3, 4
Re: check_active() with keyboards?
creedkiller wrote:brilliantly done J2Kbr. I split your code into 2 header files and now use them 1 at the top and the 2nd at the bottom of my scripts.
Slip in two header files is a very nice idea!!
ConsoleTuner Support Team
-
J2Kbr - General of the Army
- Posts: 20323
- Joined: Tue Mar 18, 2014 1:39 pm
Re: check_active() with keyboards?
antithesis wrote:What's the maximum number of keys that can be monitored?
There is no limit for that, all key could be monitored. But, for performance/optimization reasons, it is better just monitor the ones used in the script.
ConsoleTuner Support Team
-
J2Kbr - General of the Army
- Posts: 20323
- Joined: Tue Mar 18, 2014 1:39 pm
Re: check_active() with keyboards?
Could you please upload this to the online resource examples ?
Or add it to an include file that comes with gtunerIV ? This really deserves a section in the online documentation, too.
Or add it to an include file that comes with gtunerIV ? This really deserves a section in the online documentation, too.
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: check_active() with keyboards?
Definitively, I will be improving the posted code and publishing on the Online Resources.
ConsoleTuner Support Team
-
J2Kbr - General of the Army
- Posts: 20323
- Joined: Tue Mar 18, 2014 1:39 pm
Re: check_active() with keyboards?
How is key_time_release used correctly? It seems to produce random results, even in Scachi's example usage code in Online Resources.
Both the active and release states are correctly detected, and key_time_active works perfectly, but key_time_release doesn't seem to be working. Is there something I'm missing?
I worked around the problem and got exactly the result I wanted using Scachi's updated version, I'm just a tad confused about key_time_release. Is its purpose to measure time between key presses?
And why does it spit out random values in Device Monitor - is it because it's not being called correctly?
Other than that, these are brilliant additions to the kb functions and perhaps should be added to the GPC Language rather than tucked away in an obscure thread
Both the active and release states are correctly detected, and key_time_active works perfectly, but key_time_release doesn't seem to be working. Is there something I'm missing?
I worked around the problem and got exactly the result I wanted using Scachi's updated version, I'm just a tad confused about key_time_release. Is its purpose to measure time between key presses?
And why does it spit out random values in Device Monitor - is it because it's not being called correctly?
Other than that, these are brilliant additions to the kb functions and perhaps should be added to the GPC Language rather than tucked away in an obscure thread
-
antithesis - Colonel
- Posts: 1912
- Joined: Sat May 28, 2016 10:45 pm
Re: check_active() with keyboards?
antithesis wrote:How is key_time_release used correctly? It seems to produce random results, even in Scachi's example usage code in Online Resources.
Both the active and release states are correctly detected, and key_time_active works perfectly, but key_time_release doesn't seem to be working. Is there something I'm missing?
I worked around the problem and got exactly the result I wanted using Scachi's updated version, I'm just a tad confused about key_time_release. Is its purpose to measure time between key presses?
And why does it spit out random values in Device Monitor - is it because it's not being called correctly?
Other than that, these are brilliant additions to the kb functions and perhaps should be added to the GPC Language rather than tucked away in an obscure thread
I've made a more optimized version if you'd like to check it out:
you need to define the EXTRA_KEY_VAR and NUM_OF_EXTRA_KEYS before including the header though.
- Code: Select all
#ifndef EXTRA_KEY_GPC_
#define EXTRA_KEY_GPC_
#include <keyboard.gph>
#ifndef EXTRA_KEY_VAR
#define EXTRA_KEY_VAR extra_keys_list
#define NUM_OF_EXTRA_KEYS 1
uint16 EXTRA_KEY_VAR[1] = { 0 };
#endif
#ifndef NUM_OF_EXTRA_KEYS
#define NUM_OF_EXTRA_KEYS 0
#endif
#define _EXTRA_KEY_STATUS_RELEASED 0
#define _EXTRA_KEY_STATUS_JUST_RELEASED 1
#define _EXTRA_KEY_STATUS_PRESSED 2
#define _EXTRA_KEY_STATUS_JUST_PRESSED 3
uint8 extra_keys_status[NUM_OF_EXTRA_KEYS] = { 0 };
uint32 extra_keys_status_press_time[NUM_OF_EXTRA_KEYS] = { 0 };
uint32 extra_keys_status_rel_time[NUM_OF_EXTRA_KEYS] = { 0 };
main {
uint8 _extra_key_i;
for(_extra_key_i = 0; _extra_key_i < NUM_OF_EXTRA_KEYS; _extra_key_i++) {
if(key_status(EXTRA_KEY_VAR[_extra_key_i])) {
if( (extra_keys_status[_extra_key_i] == _EXTRA_KEY_STATUS_RELEASED) || (extra_keys_status[_extra_key_i] == _EXTRA_KEY_STATUS_JUST_RELEASED) ) {
extra_keys_status[_extra_key_i] = _EXTRA_KEY_STATUS_JUST_PRESSED;
extra_keys_status_press_time[_extra_key_i] = system_time();
}
else if(extra_keys_status[_extra_key_i] == _EXTRA_KEY_STATUS_JUST_PRESSED){
extra_keys_status[_extra_key_i] = _EXTRA_KEY_STATUS_PRESSED;
}
}
else {
if( (extra_keys_status[_extra_key_i] == _EXTRA_KEY_STATUS_PRESSED) || (extra_keys_status[_extra_key_i] == _EXTRA_KEY_STATUS_JUST_PRESSED) ) {
extra_keys_status[_extra_key_i] = _EXTRA_KEY_STATUS_JUST_RELEASED;
extra_keys_status_rel_time[_extra_key_i] = system_time();
}
else extra_keys_status[_extra_key_i] = _EXTRA_KEY_STATUS_RELEASED;
}
}
_extra_key_i = 0;
}
uint8 get_key_index(uint8 key) {
uint8 _extra_key_i;
for(_extra_key_i = 0; _extra_key_i < NUM_OF_EXTRA_KEYS; _extra_key_i++) {
if(EXTRA_KEY_VAR[_extra_key_i] == key) return _extra_key_i;
}
return 0;
}
bool key_event_active(uint8 key) {
return (extra_keys_status[get_key_index(key)] == _EXTRA_KEY_STATUS_JUST_PRESSED);
}
bool key_event_release(uint8 key) {
return (extra_keys_status[get_key_index(key)] == _EXTRA_KEY_STATUS_JUST_RELEASED);
}
uint32 key_time_active(uint8 key) {
if(key_status(key))
return (system_time() - extra_keys_status_press_time[get_key_index(key)]);
//else
return (extra_keys_status_rel_time[get_key_index(key)] - extra_keys_status_press_time[get_key_index(key)]);
}
uint32 key_time_release(uint8 key) {
if(key_status(key))
return (extra_keys_status_press_time[get_key_index(key)] - extra_keys_status_rel_time[get_key_index(key)]);
//else
return (system_time() - extra_keys_status_rel_time[get_key_index(key)]);
}
bool key_check_active(uint8 key, uint32 ms) {
return (key_status(key) && key_time_active(key) >= ms);
}
bool key_check_release(uint8 key, uint32 ms) {
return (!key_status(key) && key_time_release(key) >= ms);
}
#endif /* EXTRA_KEY_GPC_ */
Last edited by Buffy on Wed May 09, 2018 11:43 pm, edited 1 time in total.
-
Buffy - Lieutenant
- Posts: 422
- Joined: Wed Jul 20, 2016 5:23 am
Re: check_active() with keyboards?
Its still looks like to me the benefit is still using the input translator......
- bonefisher
- Lieutenant General
- Posts: 5413
- Joined: Thu Jan 29, 2015 10:49 am
Re: check_active() with keyboards?
Input Translators only take you part of the way. If using Apex > Titan Two, the only scriptable kb function is key_status, which allows for key press detection, but not time active, nor release state.
I defined the additional keys on line 8 and the number of keys on line 9. Nothing else was changed.
On compile, there's a GPC error on line 10 -
Buffy wrote:I've made a more optimized version if you'd like to check it out:
you need to define the EXTRA_KEY_VAR and NUM_OF_EXTRA_KEYS before including the header though.
I defined the additional keys on line 8 and the number of keys on line 9. Nothing else was changed.
On compile, there's a GPC error on line 10 -
- Code: Select all
GPC error: xkeys_opt.gph(10): syntax error, unexpected NUMBER_LITERAL, expecting IDENTIFIER or MUL_OP '0x1D'.
-
antithesis - Colonel
- Posts: 1912
- Joined: Sat May 28, 2016 10:45 pm
Re: check_active() with keyboards?
antithesis wrote:I defined the additional keys on line 8 and the number of keys on line 9. Nothing else was changed.
On compile, there's a GPC error on line 10 -
- Code: Select all
GPC error: xkeys_opt.gph(10): syntax error, unexpected NUMBER_LITERAL, expecting IDENTIFIER or MUL_OP '0x1D'.
I've uploaded a full example and attached it as a zip. I've also changed the initial code to allow mouse buttons to be tracked too.
- Attachments
-
- Extra Buttons.zip
- (2 KiB) Downloaded 88 times
-
Buffy - Lieutenant
- Posts: 422
- Joined: Wed Jul 20, 2016 5:23 am
Re: check_active() with keyboards?
Nice work Buffy!
These kb and mouse functions should be officially integrated into GPC. They're very powerful and provide far greater scripting flexibility.
We've seen a move lately in the m/kb direction and this sort of functionality capitalises on the new audience for T2.
These kb and mouse functions should be officially integrated into GPC. They're very powerful and provide far greater scripting flexibility.
We've seen a move lately in the m/kb direction and this sort of functionality capitalises on the new audience for T2.
-
antithesis - Colonel
- Posts: 1912
- Joined: Sat May 28, 2016 10:45 pm
36 posts
• Page 2 of 4 • 1, 2, 3, 4
Return to GPC2 Script Programming
Who is online
Users browsing this forum: No registered users and 79 guests