This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Anyone know of any Scala/Java libs for sane keyboard handling when using meta keys?

4 replies
Ken McDonald
Joined: 2011-02-13,
User offline. Last seen 42 years 45 weeks ago.
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
Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Anyone know of any Scala/Java libs for sane keyboard handli
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

Ken McDonald
Joined: 2011-02-13,
User offline. Last seen 42 years 45 weeks ago.
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:
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


Tomygun
Joined: 2008-11-27,
User offline. Last seen 3 years 48 weeks ago.
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:
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



Ken McDonald
Joined: 2011-02-13,
User offline. Last seen 42 years 45 weeks ago.
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:
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




Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland