Any key up event -> which key ?

DaveInDev

Member
Hi,

If I setup an "Any - key up" event, how can I get the code of the key that was just released ?
keyboard_key contains the code of the key being pressed, not released...

Another thing : I do not really understand the potential of keyboard_lastkey when we have keyboard_key.
What useful thing can be done with this keyboard_lastkey ?
 

EvanSki

King of Raccoons
keyboard_lastkey returns the code of the last key pressed,

keyboard key asks for which key to be used.

if you have an any key released, you can ask keyboard_lastkay for what key the player has used,

Note after your finished with it you should set it back to null
so you dont get errors from it not being cleared.
 

kburkhart84

Firehammer Games
I think you are going about this the wrong way. Is there any reason you want it to be just any key? Can it not be a specific key meant for a specific action, like the up arrow key jumping? Unless you have a good reason to be worrying about just any key, you are better off checking specific keys. Once you figure that out, then you can add on mapping to where you check all the keys and have the player change the input based on what they want(which preferably would include gamepad support).

Besides that, if you really do have a good reason that isn't like I'm describing above, EvanSki has given you what should be the solution.
 

DaveInDev

Member
keyboard_lastkey returns the code of the last key pressed,

keyboard key asks for which key to be used.

if you have an any key released, you can ask keyboard_lastkay for what key the player has used,

Note after your finished with it you should set it back to null
so you dont get errors from it not being cleared.
my problem is when I press 2 keys at the same time and release them in different orders.
keyboard_lastkey does not seems to contain the key effectively released when in the "Any key up" event. It just contains the last key pressed if I understand my tests...

I think you are going about this the wrong way. Is there any reason you want it to be just any key?
I understand what you say, but yes I think I have a good reason :) but maybe you can find another way to deal with it ;) : I was still trying to improve an auto-repeat feature for a text editor and also key up/down auto repeat in a list for example. That's why I need "any" key.

The fact is that the autorepeat works if I press one key at a time, but if I press one key and then another one and release in different orders, that's a mess... (and even if I should not do this, I cannot guaranty that no user will do it :rolleyes: ). I need to detect the release, because it's the end of my autorepeat.
 
I was still trying to improve an auto-repeat feature for a text editor and also key up/down auto repeat in a list for example. That's why I need "any" key.

The fact is that the autorepeat works if I press one key at a time, but if I press one key and then another one and release in different orders, that's a mess... (and even if I should not do this, I cannot guaranty that no user will do it :rolleyes: ). I need to detect the release, because it's the end of my autorepeat.
If that's the case, wouldn't you instead need to check every key instead of any? You could create an array that holds a list of all currently pressed keys. Then you iterate on it as you need to. Delete entries as needed when releasing the keys.
 

kburkhart84

Firehammer Games
There isn't anything built in that I know of, unless you can make keyboard_string work for you. It stores up to 1024 characters as typed into a string, and you can clear it as needed(like moving between different text boxes. I'm not sure if it does anything with the OS's autorepeat though.

In all honesty, I'm thinking you are going to have to handle this a little more directly, manually.
 

TheouAegis

Member
Or in the event that any key is released, loop through all the keys individually and check which one was released. Efficient? No. FPS crippling? Not really, there aren't that many keys on a keyboard typically. I do like the idea of keeping track of which keys are currently down and then only worrying about those, though. That is to me the most logical and efficient method.
 

DaveInDev

Member
If that's the case, wouldn't you instead need to check every key instead of any? You could create an array that holds a list of all currently pressed keys. Then you iterate on it as you need to. Delete entries as needed when releasing the keys.
This array is an idea : you want me to iterate in a Step event, thru all possible keycodes and check them with keyboard_check_press and keyboard_check_release ?
But this array could be wide if you consider foreign keyboards possibilities...
I want only to repeat the last key that was pressed. So If the user press A for long, it repeats after 500ms every 250ms, and if the (stupid ;)) user press B key without having released A, I want the B key to repeat instead and the A key to be forgotten.

There isn't anything built in that I know of, unless you can make keyboard_string work for you. It stores up to 1024 characters as typed into a string, and you can clear it as needed(like moving between different text boxes. I'm not sure if it does anything with the OS's autorepeat though.
In all honesty, I'm thinking you are going to have to handle this a little more directly, manually.
I already tested keyboard_string : the fact is that respond to OS autorepeat, BUT it does not record keys like up/down/pgup, etc.... And I'd like to autorepeat all these keys.

So I'm still struggling but I don't give up ! There must be a solution. I remember I already programmed this once in C++ without any problem. ;)
 
This array is an idea : you want me to iterate in a Step event, thru all possible keycodes and check them with keyboard_check_press and keyboard_check_release ?
But this array could be wide if you consider foreign keyboards possibilities...
No. You would only populate the array with currently pressed keys. Pressing a key would push the value of the key pressed to the array. Releasing a key deletes the entry associated with that key.
 

Nidoking

Member
Depending on how many keys you're tracking, you can also use a bitfield. Define macros valued 1, 2, 4, 8, 16 etc. for the different keys, and you can do things like add (or bitwise or) them together to store the complete keyboard state and & with them to determine whether a particular key is in that state.
 

DaveInDev

Member
No. You would only populate the array with currently pressed keys. Pressing a key would push the value of the key pressed to the array. Releasing a key deletes the entry associated with that key.
Oh yes, I did not understand ! Clever ! I will try it too.
Anyway I finally found a solution, where I generate "fake" intermediate press and release events that are recognized by any other object. And it is a solution that do not need the code of the released key. Here is the result :
Code:
real pressed: R  #1
simu pressed: R  #2
simu released
simu pressed: R  #3
simu released
simu pressed: R  #4
simu released
simu pressed: R  #5
simu released
simu pressed: R  #6
simu released
real released
real pressed: E  #7
simu pressed: E  #8
simu released
simu pressed: E  #9
simu released
simu pressed: E  #10
simu released
real released
If someone need, I can upload the YYZ of my test.
 
Top