This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript 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: 21048
85
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: 21048
85
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!