Using uinput to interface keyboard matrix

Asked by neema_t

First of all I'd like to thank the author for providing Python-uinput, it appears to be just what I need, but there's a problem I can't quite work out.

I have a keyboard from a 2001 PowerBook, it's an interfaceless matrix so I need to make one. In the past I've used an Arduino Leonardo to do this; a 74HC595 to cycle through the inputs and a 74HC165 to read the outputs, then the 'co-ordinate' those provide is used to reference a 2D array containing the keycodes to be sent over USB to the host.

I want to use Python-uinput running on my Raspberry Pi to replace the requirement for an Arduino (cheaper, less power, etc.). Consider the following example:
'device = uinput.Device([
    uinput.KEY_A
    ])
device.emit_click(uinput.KEY_A)'

I need to 'convert' the references to KEY_A to references to a 2D list so I can eventually write a program that shifts a bit out to a 595 (or daisy-chained 595s) then uses that shifted out value along with shifted in bits from the 165(s) to find the relevant keystroke in the 2D list, then place that value into (forgive the pseudocode) 'device.emit_click(uinput.KEY[x,y])'.

Anyway, I can't work out how to actually do that. My (relatively short) background is in electronic engineering rather than software engineering (I've been using Python for less than a month, I think) so peeking at the __init__.py is making my head spin, but as far as I can tell I'll probably need to edit how the emit_click subroutine works to do what I want, unless my lack of knowledge means I'm just not aware of a better way?

I'd really appreciate some help with this, even if it's as simple as some keywords to Google. It feels like I'm really close to achieving what I need but I'm missing this one seemingly minor detail!

Thanks for your time,
Neema

Question information

Language:
English Edit question
Status:
Answered
For:
python-uinput Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
a (tuomasjjrasanen) said :
#1

I am not 100% sure I understood the problem at hand, but I think you don't need to make any changes to python-uinput. You just need to map matrix key address to uinput event identifiers.

So, you have a matrix keyboard where each key can be addressed with a two-byte integer, right?

Then you probably have a driver, which maps those key addresses to key coordinates:

address -> (x, y)

Then you just have to define another map which maps coordinates to uinput keys:

(x, y) -> key

For example:

coord_to_key = {
 (0,1): uinput.KEY_A,
 (0,2): uinput,KEY_B,
 and so on
}

Then emitting shoule be easy:

device.emit_click(coord_to_key[x,y])

Python-uinput does (and should not) care about how events are actually emitted. It just takes care of translating method calls to real kernel events (via uinput kernel module). So you should not need to peek inside Python-uinput, just map coordinates to keys and then call emit_click()

Can you help with this problem?

Provide an answer of your own, or ask neema_t for more information if necessary.

To post a message you must log in.