1

I have an application thats, example of a auto typer.

I want to have shortcut key to trigger an event, so when I press the shortcut key anywhere without focusing on the application it still call the event.

For example, f12 is my shortcut key, when i press f12, it will trigger the event, this will happen when I'm focus the form or not.

Is that possible in Java Application?.

zBaoAnhLe
  • 253
  • 1
  • 6
  • 19
  • 3
    Do you want a system-wide shortcut (so even if your application is minimized, it still works) or just an applicatoin shortcut? The first is impossible in pure Java, while the second is very easy using Swing KeyBindings. – Guillaume Polet Jun 17 '13 at 15:09
  • Yes @GuillaumePolet, thats wat i wanted :)... – zBaoAnhLe Jun 17 '13 at 15:26
  • Im trying to look into KeyBindings atm, all the info im able to find are keybindings that work when ur focus your application, do u have any example that work for what i desire? :)..thanks in advance if u do. – zBaoAnhLe Jun 17 '13 at 15:28
  • 1
    The comment was that you can't do this in Java when the application doesn't have focus. You need to use JNI or JNA and I have no idea how to do this. – camickr Jun 17 '13 at 15:30
  • Apart from [JNI](http://docs.oracle.com/javase/6/docs/technotes/guides/jni/), you can also look into, [JNativeHooks](https://code.google.com/p/jnativehook/). You might also find this [thread](http://stackoverflow.com/q/14118734/1057230) useful :-) – nIcE cOw Jun 17 '13 at 15:55
  • @zBaoAnhLe What do you want? I am asking "do you want this or that?" and you answer me "Yes". I still don't know which one you want. – Guillaume Polet Jun 17 '13 at 15:58
  • 1) Please use the correct spelling for words like 'you', 'your' & 'please'. This makes it easier for people to understand and help. 2) Please add an upper case letter at the start of sentences. Also use a capital for the word I, and abbreviations and acronyms like JEE or WAR. This makes it easier for people to understand and help. – Andrew Thompson Jun 17 '13 at 17:44
  • @GuillaumePolet i want a system-wide shortcut (so even if your application is minimized, it still works) – zBaoAnhLe Jun 17 '13 at 23:24

1 Answers1

2

Yes. Look into the Swing Action. There is more info here:

http://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html

Lee Meador
  • 12,829
  • 2
  • 36
  • 42
  • 1
    Action and Key Bindings are always good, but the application must have focus for this to work. – camickr Jun 17 '13 at 15:13