• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ALT_MASK and CTRL_MASK

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have to make a menu with a keyboard accelerator key combination of Ctrl+Alt+A. the following line will make a keyboard shortcut of Ctrl+A:

jmiAdd.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));

on the menu will be the light blue letters "Ctrl-A" next to the menu entry, plus you can press Ctrl-A at any time to execute the instruction.

by changing CTRL_MASK to ALT_MASK, you change it to "Alt-A".

what i want is to require Ctrl and Alt and A to be pressed simultaneously to execute the instruction. my first guess was CTRL_ALT_MASK, but that didn't work.

i could kluge the code testing for control and alt pressed at the same time, but i want the proper accelerator note "Ctrl+Alt-A" to show up on the menu beside the menu entry.

have been to several websites on keystroke handling but none talk about combinations.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Swing...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that CTRL_MASK and ALT_MASK are just int's and I seem to remember adding ints together to make this work:



Let me know if that worked.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello G Rachar,
Sir i have seen your problem and also Mr. Gregg Bolinger Solution i.e.

jmiAdd.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK+ALT_MASK));

but that is not working and it was wrong u can use either this

jmiAdd.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK + ActionEvent.ALT_MASK));

or
jmiAdd.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, 10));

10 because 10 is a combination of 8 + 2

8 is ALT

2 is CTRL
now it's works ,have a look, and all the best
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ravi is correct. I had a typo in my code. I left out the ActionEvent part just before ALT_MASK.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic