- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Anyone know of any Scala/Java libs for sane keyboard handling when using meta keys?
Sat, 2011-05-14, 04:10
Here's an example of what's currently driving me up the wall.
In programs such as, say, browsers, it's common to assign the key combo "alt -" to reduce font size, and "alt +" (which is to say, "shift alt +" on US keyboards) to increase font size. I want to make it easy to specify such key combos, and to handle them when the user activates them
If only life were this easy. It turns out that pressing "alt -" on a US keyboard actually generates a "–" (short dash) character, while pressing "shift alt +" generates "±" (the plus or minus sign.) And there is, as far as I can tell, no easy way of knowing what symbol (the one printed on the key) was actually pressed, because the only other applicable key info in a key event is a numerical code representing the physical key that was pressed--and the same physical key may have different symbols on different keyboard styles.
Now I know that programs manage to do this somehow, but I'm sure not seeing an easy solution. Is there a library out there I could use. Could someone suggest a different approach? This has got me completely stopped for the time being.
Thanks,Ken
In programs such as, say, browsers, it's common to assign the key combo "alt -" to reduce font size, and "alt +" (which is to say, "shift alt +" on US keyboards) to increase font size. I want to make it easy to specify such key combos, and to handle them when the user activates them
If only life were this easy. It turns out that pressing "alt -" on a US keyboard actually generates a "–" (short dash) character, while pressing "shift alt +" generates "±" (the plus or minus sign.) And there is, as far as I can tell, no easy way of knowing what symbol (the one printed on the key) was actually pressed, because the only other applicable key info in a key event is a numerical code representing the physical key that was pressed--and the same physical key may have different symbols on different keyboard styles.
Now I know that programs manage to do this somehow, but I'm sure not seeing an easy solution. Is there a library out there I could use. Could someone suggest a different approach? This has got me completely stopped for the time being.
Thanks,Ken
Sun, 2011-05-15, 23:27
#2
Re: Anyone know of any Scala/Java libs for sane keyboard handli
Just a plain "mainWindow.addKeyListener(new KeyAdapter {...})
On May 15, 2011, at 3:00 PM, Naftoli Gugenheim wrote:
On May 15, 2011, at 3:00 PM, Naftoli Gugenheim wrote:
Not on my US keyboard...
Anyway, how are you getting the input? Swing? Browser JavaScript? Console?
On Fri, May 13, 2011 at 11:10 PM, Ken McDonald <ykkenmcd@gmail.com> wrote:
Here's an example of what's currently driving me up the wall.
In programs such as, say, browsers, it's common to assign the key combo "alt -" to reduce font size, and "alt +" (which is to say, "shift alt +" on US keyboards) to increase font size. I want to make it easy to specify such key combos, and to handle them when the user activates them
If only life were this easy. It turns out that pressing "alt -" on a US keyboard actually generates a "–" (short dash) character, while pressing "shift alt +" generates "±" (the plus or minus sign.) And there is, as far as I can tell, no easy way of knowing what symbol (the one printed on the key) was actually pressed, because the only other applicable key info in a key event is a numerical code representing the physical key that was pressed--and the same physical key may have different symbols on different keyboard styles.
Now I know that programs manage to do this somehow, but I'm sure not seeing an easy solution. Is there a library out there I could use. Could someone suggest a different approach? This has got me completely stopped for the time being.
Thanks,Ken
Mon, 2011-05-16, 00:57
#3
Re: Anyone know of any Scala/Java libs for sane keyboard handli
I think you are using keyTyped(...) if that's the case you should try keyPressed(...) and yeyReleased(...), keyTyped is for text while the others are for keys. Try checking the event against VK_MINUS and checking for the VK_ALT modifier.
On Sun, May 15, 2011 at 7:25 PM, Kenneth McDonald <ykkenmcd@gmail.com> wrote:
On Sun, May 15, 2011 at 7:25 PM, Kenneth McDonald <ykkenmcd@gmail.com> wrote:
Just a plain "mainWindow.addKeyListener(new KeyAdapter {...})
On May 15, 2011, at 3:00 PM, Naftoli Gugenheim wrote:Not on my US keyboard...
Anyway, how are you getting the input? Swing? Browser JavaScript? Console?
On Fri, May 13, 2011 at 11:10 PM, Ken McDonald <ykkenmcd@gmail.com> wrote:
Here's an example of what's currently driving me up the wall.
In programs such as, say, browsers, it's common to assign the key combo "alt -" to reduce font size, and "alt +" (which is to say, "shift alt +" on US keyboards) to increase font size. I want to make it easy to specify such key combos, and to handle them when the user activates them
If only life were this easy. It turns out that pressing "alt -" on a US keyboard actually generates a "–" (short dash) character, while pressing "shift alt +" generates "±" (the plus or minus sign.) And there is, as far as I can tell, no easy way of knowing what symbol (the one printed on the key) was actually pressed, because the only other applicable key info in a key event is a numerical code representing the physical key that was pressed--and the same physical key may have different symbols on different keyboard styles.
Now I know that programs manage to do this somehow, but I'm sure not seeing an easy solution. Is there a library out there I could use. Could someone suggest a different approach? This has got me completely stopped for the time being.
Thanks,Ken
Mon, 2011-05-16, 01:17
#4
Re: Anyone know of any Scala/Java libs for sane keyboard handli
It's been a while since I tried things at that level, but it still doesn't work. IIRC, the reasons is like this:
keyPressed and keyReleased give info about the _physical_ key being pressed or released--but this is no good for trying to identify "shift alt +", as the _physical_ key for + on a US keyboard is actually =, and might be something different on a non-US keyboard.
AFAIK, there is simply no way of doing this with the info provided by AWT. Very weird.
Cheers,Ken
On May 15, 2011, at 6:51 PM, Tomás Lázaro wrote:
keyPressed and keyReleased give info about the _physical_ key being pressed or released--but this is no good for trying to identify "shift alt +", as the _physical_ key for + on a US keyboard is actually =, and might be something different on a non-US keyboard.
AFAIK, there is simply no way of doing this with the info provided by AWT. Very weird.
Cheers,Ken
On May 15, 2011, at 6:51 PM, Tomás Lázaro wrote:
I think you are using keyTyped(...) if that's the case you should try keyPressed(...) and yeyReleased(...), keyTyped is for text while the others are for keys. Try checking the event against VK_MINUS and checking for the VK_ALT modifier.
On Sun, May 15, 2011 at 7:25 PM, Kenneth McDonald <ykkenmcd@gmail.com> wrote:Just a plain "mainWindow.addKeyListener(new KeyAdapter {...})
On May 15, 2011, at 3:00 PM, Naftoli Gugenheim wrote:Not on my US keyboard...
Anyway, how are you getting the input? Swing? Browser JavaScript? Console?
On Fri, May 13, 2011 at 11:10 PM, Ken McDonald <ykkenmcd@gmail.com> wrote:
Here's an example of what's currently driving me up the wall.
In programs such as, say, browsers, it's common to assign the key combo "alt -" to reduce font size, and "alt +" (which is to say, "shift alt +" on US keyboards) to increase font size. I want to make it easy to specify such key combos, and to handle them when the user activates them
If only life were this easy. It turns out that pressing "alt -" on a US keyboard actually generates a "–" (short dash) character, while pressing "shift alt +" generates "±" (the plus or minus sign.) And there is, as far as I can tell, no easy way of knowing what symbol (the one printed on the key) was actually pressed, because the only other applicable key info in a key event is a numerical code representing the physical key that was pressed--and the same physical key may have different symbols on different keyboard styles.
Now I know that programs manage to do this somehow, but I'm sure not seeing an easy solution. Is there a library out there I could use. Could someone suggest a different approach? This has got me completely stopped for the time being.
Thanks,Ken
Anyway, how are you getting the input? Swing? Browser JavaScript? Console?
On Fri, May 13, 2011 at 11:10 PM, Ken McDonald <ykkenmcd@gmail.com> wrote: