2 registered members (AndrewAMD, juanex),
1,247
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Keybinds
[Re: Reconnoiter]
#461016
07/22/16 17:58
07/22/16 17:58
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
Well, I'm not a big fan of the on_...-events and I don't think that there's an event for all keys on a normal Keyboard. Using a custom input system seems more elegant and cleaner to me. @Reconnoiter: The method I'm going to use is similar to the one you posted. However, I think using strings as keycodes adds unnecessary complexity (parsing the string on every poll...) and makes it harder to implement actual ingame binding (which is important to me aswell). Edit: I just saw that theres a reverse function for key_for_str() (str_for_key(), I searched for key_to_str()...) So ingame binding with your method wouldn't be a problem. But it's still just wasted performance imo.. going from the scancode to the key-string just to do the reverse for every key poll
Last edited by Kartoffel; 07/22/16 18:24.
POTATO-MAN saves the day! - Random
|
|
|
Re: Keybinds
[Re: Kartoffel]
#461019
07/22/16 19:29
07/22/16 19:29
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
Serious User
|
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
@Reconnoiter: The method I'm going to use is similar to the one you posted. However, I think using strings as keycodes adds unnecessary complexity (parsing the string on every poll...) and makes it harder to implement actual ingame binding (which is important to me aswell). Edit: I just saw that theres a reverse function for key_for_str() (str_for_key(), I searched for key_to_str()...) So ingame binding with your method wouldn't be a problem. But it's still just wasted performance imo.. going from the scancode to the key-string just to do the reverse for every key poll , does your method allow modifying mouse buttons? (if so could you post a simple example how you do it now? (pretty please with sugar ontop))
|
|
|
Re: Keybinds
[Re: Reconnoiter]
#461021
07/22/16 19:54
07/22/16 19:54
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
you have all the key related variables sorted by scancode into arrays already.
int _i = 1;
for ( ; _i<89; _i+=1 )
{
key_set ( _i, myEvent );
if ( *(&on_esc+_i-1) != myEvent )
error ( str_cat ( str_for_key ( NULL, _i ), " is not into an array???" ) );
key_set ( _i, NULL );
}
while ( !key_esc )
{
for ( _i=1; _i<89; _i+=1 )
{
if ( *(&key_esc+_i-1) == 1 )
draw_text ( str_cat ( str_for_key ( NULL, _i ), " key pressed" ), 10, 10, COLOR_WHITE );
}
wait(1);
}
but those arrays are not public and due to engines frequent updates and constant evolution use these things is a high risk [buahahaha] Anyway, if it is a matter of customization, you can use pointers for actions.
var *keyUp = &key_w;
...
if ( *keyUp ) {...}
I don't think that there's an event for all keys on a normal Keyboard. there are...
Last edited by txesmi; 07/22/16 20:21.
|
|
|
Re: Keybinds
[Re: txesmi]
#461022
07/22/16 20:24
07/22/16 20:24
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
but those arrays are not public and due to engines frequent updates and constant evolution use these things is a high risk [buahahaha] shots fired @Reconnoiter: I haven't even started writing the code but it shouldn't be too different when using mouse buttons...
POTATO-MAN saves the day! - Random
|
|
|
Re: Keybinds
[Re: txesmi]
#461025
07/22/16 21:46
07/22/16 21:46
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
Serious User
|
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
@txesmi, ty! but those arrays are not public and due to engines frequent updates and constant evolution use these things is a high risk [buahahaha]
, [black van stopping at the door]
|
|
|
Re: Keybinds
[Re: Reconnoiter]
#461029
07/22/16 23:37
07/22/16 23:37
|
Joined: Jul 2016
Posts: 9
JackPell
Newbie
|
Newbie
Joined: Jul 2016
Posts: 9
|
I have an init_keys() function that loads the scan codes for the control keys from external file and set them to variables with meaningful names (like key_jump_scan, key_shoot_scan .. etc.) ,then update_keys() that runs every frame that sets the state of every key to another kind of variable (like: key_jump, key_shoot ... etc.) using key_pressed(scan_code) function:
while(1)
{
...
key_jump = key_pressed(key_jump_scan); //key_jump_scan was already set to the scan code of the desired key in the previous init_keys() function
...
wait(1);
}
Then, inside the main code that controls whatever kind of key-based behaviour, i use the key_something variable like:
...
movement_speed.x = (key_forward-key_backward)*10*time_step;
...
|
|
|
Re: Keybinds
[Re: JackPell]
#461030
07/22/16 23:57
07/22/16 23:57
|
Malice
Unregistered
|
Malice
Unregistered
|
Key_pressed with the -1 ability and also key_pressed to key_lastpressed and key_any(x) == X and also the key_hit.
But if you have the pre-mapped key in a array if(i[0]) jump and if(i[1]) walk then you can remap by recording on the menu page the replacement string i[0]=key_for_str() then forever cycle your array in each frame. But remember to reset key_pressed with the -1 where needed or compare to key_last where needed. And key any() actually helps at times.
Last edited by Malice; 07/22/16 23:59.
|
|
|
Re: Keybinds
[Re: ]
#461045
07/23/16 17:31
07/23/16 17:31
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
another related question:
Does anyone know how to get the input from a gamepad's d-pad?
POTATO-MAN saves the day! - Random
|
|
|
Re: Keybinds
[Re: alibaba]
#461060
07/24/16 08:58
07/24/16 08:58
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
I'm using superKu's Xinput dll yes, I'm using this one, too (thanks again, superku ) However, I also want to support older DirectInput game controllers...
POTATO-MAN saves the day! - Random
|
|
|
|