Hi
I need to find out whether the shift key is pressed. I cannot use events for this, I need to poll the keyboard. Unfortunately I don't know how. Any tips?
Thx in advance
Printable View
Hi
I need to find out whether the shift key is pressed. I cannot use events for this, I need to poll the keyboard. Unfortunately I don't know how. Any tips?
Thx in advance
i didn't look at the api, but can't you just implement an action listener and see if the even was 'shift' key was pressed?
--770
Hes said that no events can be used. :lol:
haha, sorry about that, not reading completly...:blush:
this is a puzzle, is it even possible. cause you can't really use any system commands to detect keypress.. interrupts or window functions...
--770
Why couldn't you just use System.in to get the value of what is pressed. Then compare that value to the integer value of the shift key?
Because it's a GUI app.
The problem is not imminent anymore, but I'm still interested in a solution.
I looked around on Sun's site, and there doesn't seem to be a way.
You may need to resort to wrapping a call to GetASyncKeyState (for Windows anyway). Is that JNI? I remember from a while back but I forget the exact process.
The thing is supposed to run everywhere, so that's not an option.
But I've worked around the problem anyway. Thanks to all who tried to help.
just wondering why you can't use events?!
if you just don't want to get bogged down with events you could maybe just implement it in one class, then have all your other classes polling the class that is monitoring the keyboard.
Keep a FIFO queue in the class with all the key events in it, then once everything has polled it you could flush the queue....
possibly.....
Other than that i don't actually know of a way to do it by polling:confused:
By now I've found a way to do it without polling. My problem was that I already reacted to one event (a window manipulation) but needed to know if the shift key was pressed.