5

I have a Java Swing app in Which I have been able to set shortcut keys using the following piece of code. For example Ctrl+K.

keyHelp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK));
keyHelp.setMnemonic((int) 'K');//This is the Line I need Help in 

I just can't figure out how to add the same using F1 key as the shortcut... Could anyone please help?

Stanley Mungai
  • 4,044
  • 30
  • 100
  • 168

3 Answers3

5

Using Action, as shown here and here, can make these settings easier to manage. Also consider getMenuShortcutKeyMask() instead of assuming Event.CTRL_MASK.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
4

use,

KeyEvent.VK_F1

I think it will help you.

Milan
  • 245
  • 3
  • 11
1

If you need to make your shortcut key just "F1" without CTRL, It should be like this,

keyHelp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));