Click to See Complete Forum and Search --> : Polling the Keyboard
CornedBee
Mar 14th, 2004, 04:00 AM
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
delta770
Mar 16th, 2004, 06:27 PM
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
Dillinger4
Mar 16th, 2004, 11:36 PM
Hes said that no events can be used. :lol:
delta770
Mar 16th, 2004, 11:47 PM
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
Dillinger4
Mar 17th, 2004, 09:57 PM
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?
CornedBee
Mar 18th, 2004, 10:04 AM
Because it's a GUI app.
The problem is not imminent anymore, but I'm still interested in a solution.
crptcblade
Mar 18th, 2004, 10:24 AM
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.
CornedBee
Mar 18th, 2004, 10:33 AM
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.
Andy_Hollywood
Apr 2nd, 2004, 02:45 AM
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:
CornedBee
Apr 2nd, 2004, 03:23 AM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.