Python Forum
Keyboard events - incl. numpad
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keyboard events - incl. numpad
#1
Hi,

I need to be able to listen for and send keyboard inputs, even when the python application isn't in focus. So far I've looked at 'keyboard' and 'pynput'. They looked promising however often I'll need to listen to and send numpad keys, and for example in the packages mentioned the code for numpad 0 is the same as the regular number 0 and so on. I need to do this as another program globally listens for these hotkeys, and it differentiates between regular buttons and the numpad, for example if you set a hotkey in that program as 0 on the numpad, it will display in the menu as "NumPad0", and sending an event for the regular number 0 will not trigger it.

Kind Regards,
Kaine
Reply
#2
see: https://pypi.org/project/pynput/

Quote: even when the python application isn't in focus

but the python program must remain active.
Reply
#3
Hi,

As I mentioned in my original post I have tried pynput but it does not seem to differentiate the numpad to the regular numbers. Is there something about pynput that I'm missing?

Thanks
Reply
#4
Using this module you can do whatever you want: https://pypi.org/project/teletype/

First you need a list of scan codes, they can be found here: https://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
or here: http://www.ee.bgu.ac.il/~microlab/MicroL...nCodes.htm
the first is better because it contains information on each code.
Reply
#5
That doesn't seem to differentiate numpad keys, the code for numpad 0 is just the code for insert for example and won't trigger the other programs hotkeys.

So far I've managed to send out keypresses using VK codes and the win32api, it looks like I can also register global hotkeys.

Now I need a way to globally listen for VK codes, any ideas?
Reply
#6
the code 0 is not a scan code.
In fact there are many different versions of keyboards, depending on country
a typical layout would have the following scan codes:
Output:
--- --------------- --------------- --------------- ----------- | 01| | 3B| 3C| 3D| 3E| | 3F| 40| 41| 42| | 43| 44| 57| 58| |+37|+46|+45| --- --------------- --------------- --------------- ----------- ----------------------------------------------------------- ----------- --------------- | 29| 02| 03| 04| 05| 06| 07| 08| 09| 0A| 0B| 0C| 0D| 0E| |*52|*47|*49| |+45|+35|+37| 4A| |-----------------------------------------------------------| |-----------| |---------------| | 0F| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 1A| 1B| 2B| |*53|*4F|*51| | 47| 48| 49| | |-----------------------------------------------------------| ----------- |-----------| 4E| | 3A| 1E| 1F| 20| 21| 22| 23| 24| 25| 26| 27| 28| 1C| | 4B| 4C| 4D| | |-----------------------------------------------------------| --- |---------------| | 2A| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 35| 36| |*4C| | 4F| 50| 51| | |-----------------------------------------------------------| ----------- |-----------|-1C| | 1D|-5B| 38| 39|-38|-5C|-5D| -1D| |*4B|*50|*4D| | 52| 53| | ----------------------------------------------------------- ----------- ---------------
the keyboard will emit several codes to identify a single key, for example Enter key actually outputs the sequence FA F0 BA
here's a good writeup: http://www.quadibloc.com/comp/scan.htm

post 84 here seems to have some code that will work.
https://stackoverflow.com/questions/1356...-in-python
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  wait for the first of these events Skaperen 4 1,933 Mar-07-2022, 08:46 PM
Last Post: Gribouillis
  reverse list, incl. nested list Livne_ye 3 3,136 May-04-2019, 12:34 PM
Last Post: Livne_ye
  Simulating events using Hawkes akshit2291 1 2,138 Sep-25-2018, 04:17 AM
Last Post: Larz60+
  win32com Events not catching dageci 0 3,744 Aug-06-2018, 03:18 PM
Last Post: dageci

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020