Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Testing if key is down  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I want to test if a key is down inside an 'if'.. eg


But I only know how to get a key press to invoke a method, eg keyPressed(KeyEvent ke) using KeyListener, or KeyAdapter.

Is there anyway I can do it as described?

Thanks for any help
 
Campbell Ritchie
Sheriff
Posts: 53720
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A KeyAdapter is a special kind of KeyListener.

You should be able to find out the keys pressed from the KeyEvent. Try going through the KeyEvent API page; note there is a link to a tutorial on that page. You should be able to find out whether the shift or alt (=meta) or ctrl keys are pressed, too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!