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

Checking for CTRL+s when a JButton is pushed  RSS feed

 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to be able to check when a JButton is pushed whether the CTRL and "S" keys are both pushed. Right now I only check for the CTRL or SHFT buttons using he following code:



I just can't seem to figure out to check whether the SHFT+S or SHFT+c keys are both pressed when the JButton is pressed. Any ideas?

Thanks,
Dave
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that a KeyListener will help you out a bit more. You'll need to store whether or not the S is still pressed though.
 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
I think that a KeyListener will help you out a bit more. You'll need to store whether or not the S is still pressed though.


Ya, I think I've got an idea now. Using a key listener I'll keep track when either the "S" or "C" key are pressed. And then when the JButton is pressed I'll simply check whether the "S" key is also pressed.

Thanks!
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use booleans for both S and C. After all, you can have both pressed at the same time.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!