|
-
Mar 14th, 2004, 05:00 AM
#1
Polling the Keyboard
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
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 16th, 2004, 07:27 PM
#2
Addicted Member
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
-
Mar 17th, 2004, 12:36 AM
#3
Dazed Member
Hes said that no events can be used.
-
Mar 17th, 2004, 12:47 AM
#4
Addicted Member
haha, sorry about that, not reading completly...
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
-
Mar 17th, 2004, 10:57 PM
#5
Dazed Member
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?
-
Mar 18th, 2004, 11:04 AM
#6
Because it's a GUI app.
The problem is not imminent anymore, but I'm still interested in a solution.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 18th, 2004, 11:24 AM
#7
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.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 18th, 2004, 11:33 AM
#8
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 2nd, 2004, 03:45 AM
#9
Addicted Member
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
-
Apr 2nd, 2004, 04:23 AM
#10
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|