• Post Reply Bookmark Topic Watch Topic
  • New Topic

KeyAdapter in java  RSS feed

 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,

My problem is that i can't realize how to detect multiple key detection

By that i mean that i want to check if i press CTRL AND ALT AND DELETE I want the input to be like that - "CTRL + ALT + DELETE"
And so on , if i keep pressing keys it'll add "+" And the key it pressed.

Thanks in advance.


 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, are you sure KeyAdapter is the right choice? To listen for specific key combinations, an input action with a specific KeyStroke is probably a better idea.

If you still want to do this, then use a set to store the keys that are pressed. In keyPressed you add the key to the set, in keyReleased you remove it again. In between you have all the pressed keys in your set.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever method you use, you can probably not catch Ctrl + Alt + Delete - this is a special key combination on PCs that is handled directly by the OS, and for security reasons applications cannot catch this key combination.

To explain why this would be a security hole: Suppose that you press Ctrl + Alt + Delete and an application shows a lock screen that looks exactly like the lock screen of Windows. It then shows a text box to enter your password to unlock the screen. A user enters his/her password, but not to Windows itself, but to the application. The application has now stolen the user's password.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!