I want to add a sort of cheat code to a program I am writing. I was wondering how I could do this. For example when I am anywhere on the screen I want to be able to press a certain key combination for example ctl + alt + w, and get some action from that. My guess would be using a keylistener and adding it to the frame. Any help would be appreciated.
Thanks,
class cheat implements KeyListener{
public void keyPressed(KeyEvent e){
char key = e.getKeyChar();
System.out.println(key);
}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
}
Yes you would add a keylistener. Inside your trigger for your listener, you can pass the KeyEvent to a secondary method to encapsulate the logic, then act appropriately.