How to send numpad keys?

786 views
Skip to first unread message

Lissanro Rahyen

unread,
Jan 5, 2014, 8:01:34 AM1/5/14
to autoke...@googlegroups.com
I guess it would something like keyboard.send_key("<enter>"), but I did not find codes for numpads keys so I would be grateful for an example how to send numpad keys (like numpad0, numpad+, etc.).

Joe

unread,
Jan 5, 2014, 1:35:41 PM1/5/14
to autoke...@googlegroups.com
Welcome.

I looked here and didn't see them either.
https://code.google.com/p/autokey/wiki/SpecialKeys

Until someone else gives a better answer, here's something that might
give you a clue.
Make sure autokey is not running.
Run autokey-gtk -l from a console
press a couple of your numeric keys
stop autokey
look at the end of the log output for where autokey detected your
keypresses and see what it called them.

You can also get key codes using xev. In either case, you still have to
figure out how to tell autokey about them.

If you know enough Python, you might be able to use that in a macro to
insert your key code into the clipboard and then get it into autokey by
reading the clipboard and passing that to keyboard.send_key.

These are definitely kludges, but they might work or at least get you
closer to a solution.

HTH

Joe
> --
> You received this message because you are subscribed to the Google
> Groups "autokey-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autokey-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Joe

unread,
Jan 5, 2014, 2:23:02 PM1/5/14
to autoke...@googlegroups.com
I thought about it a little bit more.

I'm don't know much Python, but I bet keyboard.send_key will take some
kind of constant with the appropriate value for your numeric key(s). You
can either just try things or read the autokey source code to see what
it wants.

Joe

L. Rahyen

unread,
Jan 5, 2014, 3:10:45 PM1/5/14
to autoke...@googlegroups.com

> Run autokey-gtk -l from a console

> press a couple of your numeric keys

> stop autokey

> look at the end of the log output for where autokey detected your

> keypresses and see what it called them.

I do not have autokey-gtk installed so I ran autokey-qt -l instead. When I press numpad0 it prints:

"Raw key: '<np_insert>', modifiers: [], Key: <np_insert>"

When I tried keyboard.send_key("<np_insert>") it sent numpad "insert" key instead of numpad0.

 

> You can either just try things or read the autokey source code to see what it wants.

I ran "apt-get source autokey-qt" and looked into the source code. Only numeric numpad key I found is <np_5> but it turned out to be non-numeric - it does almost nothing like I have numlock turned off. It seems like numpad support is partial - only numpad keys with numlock turned off are supported (it does not matter if numlock is turned on or turned off on my keyboard - autokey ignores it).

 

Currently I use this line to send numpad0:

system.exec_command("xdotool key KP_0")

 

Hopefully full support for numpad keys will be added in future version of autokey.

Joe

unread,
Jan 5, 2014, 10:18:01 PM1/5/14
to autoke...@googlegroups.com
Cool that it works for you. (I assume that code is in your keyboard macro.)

I wonder what it would do if you bracketed <np_insert> with <numlock>
before and after. I also wonder if <np_0> would work or come back as an
error.

BTW, I don't currently have a working version of autokey on my system or
I would try these things myself.

If you know any Python programmers, see if any of them might be
interested in working on autokey.

Joe

L. Rahyen

unread,
Jan 7, 2014, 5:22:15 PM1/7/14
to autoke...@googlegroups.com

On Sunday 05 January 2014 22:18:01 Joe wrote:

> I wonder what it would do if you bracketed <np_insert> with <numlock>

> before and after.

Nothing useful unfortunately. I still get numpad_insert instead of numpad_0.

 

> I also wonder if <np_0> would work or come back as an error.

In the source only np_5 is mentioned, so np_0, np_1, etc. will not work. In the source:

http://code.google.com/p/autokey/source/browse/trunk/src/lib/interface.py?r=430

I can see XK_TO_AK_NUMLOCKED but missing np_0-4 and np_6-9 are strange... I guess something was left unfinished and it does not work.

 

> Cool that it works for you. (I assume that code is in your keyboard macro.)

Yes, that's line from my autokey script. So this is minor problem because workaround is so easy. I just thought autokey can do this too so I decided to ask. But apparently not yet.

Reply all
Reply to author
Forward
0 new messages