Results 1 to 10 of 10

Thread: Polling the Keyboard

  1. #1

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.

  2. #2
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181
    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

  3. #3

  4. #4
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181
    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

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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?

  6. #6

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  7. #7
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  8. #8

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  9. #9
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222
    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

  10. #10

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width