Discussion:
[python-win32] getting Windows key codes
Eric S. Johansson
2015-03-30 20:40:13 UTC
Permalink
https://docs.google.com/drawings/d/1M-TzfRaSaAhFXQk1OmcmHNOaW31_7W_7q0bf8CAJqSw/edit
Set with some help for a friend of mine, I was able to implement the
system illustrated above. As a result I can mostly successfully use
speech recognition on Windows to dictate text into a variety of Linux
applications. I discover some problems which make me think that the
right solution is to capture windows events/key codes and translate them
into the lyrics equivalents. This way I think I can handle many of the
special function keys more easily.

My question is two parts, first is how do I get access to these key
codes (equivalent to what's in the Python uinput module). And what kind
of framework does Windows demand (text window etc.) in order to be able
to expose these key codes.

I thought this should be a question Google can answer but I haven't
found the right question.

Thanks for any help or pointers
--- eric
Tim Roberts
2015-03-30 21:50:51 UTC
Permalink
Post by Eric S. Johansson
Set with some help for a friend of mine, I was able to implement the
system illustrated above. As a result I can mostly successfully use
speech recognition on Windows to dictate text into a variety of Linux
applications. I discover some problems which make me think that the
right solution is to capture windows events/key codes and translate them
into the lyrics equivalents. This way I think I can handle many of the
special function keys more easily.
I assume that should be "Linux", rather than "lyrics".

If you are doing speech recognition, where do Windows events and key
codes come into play?
Post by Eric S. Johansson
My question is two parts, first is how do I get access to these key
codes (equivalent to what's in the Python uinput module). And what kind
of framework does Windows demand (text window etc.) in order to be able
to expose these key codes.
Your question isn't clear. What key codes and events do you want to
grab? Perhaps you should give us a couple of specific scenarios that
describe what you want to have happen.
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
Eric S. Johansson
2015-03-30 23:41:47 UTC
Permalink
Post by Tim Roberts
Post by Eric S. Johansson
Set with some help for a friend of mine, I was able to implement the
system illustrated above. As a result I can mostly successfully use
speech recognition on Windows to dictate text into a variety of Linux
applications. I discover some problems which make me think that the
right solution is to capture windows events/key codes and translate them
into the lyrics equivalents. This way I think I can handle many of the
special function keys more easily.
I assume that should be "Linux", rather than "lyrics".
That's one of the ways you can tell someone is using speech recognition.
If things look weird, just read it out loud and try to listen to what
you're saying
Post by Tim Roberts
If you are doing speech recognition, where do Windows events and key
codes come into play?
It's one of these side effect things. Speech recognition either generate
straight text or in the case of a matching grammar, perform some action.
As far as I can tell, NaturallySpeaking shoves events onto the Windows
input queue. I think there may be two different types because in one
case they have the general form that usually works but they also have a
system input stream which is much lower down. I am guessing that they
translate the normal Latin one character set spoken into Windows events
much in the same way that I do in my code.
Post by Tim Roberts
Post by Eric S. Johansson
My question is two parts, first is how do I get access to these key
codes (equivalent to what's in the Python uinput module). And what kind
of framework does Windows demand (text window etc.) in order to be able
to expose these key codes.
Your question isn't clear. What key codes and events do you want to
grab? Perhaps you should give us a couple of specific scenarios that
describe what you want to have happen.
Good idea. the problem that drove me to the conclusion is
differentiating between backspace and delete not to mention control H in
Emacs. There are also things like cut and paste whose key sequences are
variable depending on the application.

The ASCII character for delete is 7f
it's keycode in uinput/ev.py is KEY_DELETE = (0x01, 111)
the ASCII character for backspace is 08
it's keycode in uinput/ev.py is KEY_BACKSPACE = (0x01, 14)
Lenox equivalent
In a nutshell, what I want to do is given a Windows keycode, translate
the keycode to the linux equivalent. I'm starting with handling the
control H problem.

The keycode gives me access to a whole bunch of additional information
about which characters have been spoken versus the characters one can
type. For example when I was trying to figure out the difference between
backspace and delete inside of Emacs, I did the usual ^q to try and trap
the next character and I always get the escape character. If the key
codes are what's being used instead of the ASCII character equivalents
that would explain why the delete key and control H still available for
help.

If I am able to translate from Windows key codes to the next key codes
then I will have a less lossy conversion (theoretically and be able to
handle more of the non-traditional keyboard characters like function
keys and meta-keys etc.

As for what key codes I need to trap and convert, it's a big I don't
know. This exploration process is been one big "what the hell were they
thinking" when I see what Nuance generates in response to what I say.

--- eric
reckoner
2015-03-31 22:17:58 UTC
Permalink
The easiest thing to do is follow the instructions here:

http://ahkscript.org/docs/KeyList.htm#SpecialKeys

And use the keyboard hook to report the keystrokes. Then, you can use

https://github.com/t4ngo/dragonfly

To do all the key re-mapping. by the way, the dragonfly source code has
all the ctypes calls to interact with the keyboard. Just about every key
and key combination you can think of is in there.

I hope that helps.

Loading...