0

For my DIY access control system, I'm running Debian on a Raspberry Pi attached to a MagStripe card reader. When a card is swiped, the reader writes the data from the magnetic stripe over the USB port by acting like a keyboard. For example, plug it into your computer, open a text editor, and swipe a card and you'll see a string of data printed out like you typed it with your keyboard.

Simple connection diagram:

Client <--ssh--> Host + card reader

The only problem is that I'm running my Python script over ssh, which doesn't directly hear the keyboard input.

How can I get Python to listen to the keyboard events coming from the MagStripe reader? (do I need to use a keylogger? PyGame's keyboard bindings?)

Thanks for the help!

2
  • So which machine has the card reader, the client or the host? Commented Jul 13, 2012 at 15:23
  • The host has the card reader. Commented Jul 13, 2012 at 15:31

2 Answers 2

2

On Linux, USB keyboards can be accessed via /dev/input.

See: format of /dev/input/event*? - the answers to that question include two different Python modules for getting events, and links to more documentation.

To translate from key codes to ASCII, see How can I translate Linux keycodes from /dev/input/event* to ASCII in Perl?

You will probably need to be root, or change the permissions on /dev/input.

Sign up to request clarification or add additional context in comments.

Comments

0

It may be worth dividing the program into a two pieces: one as a service that starts at boot time on the raspberry pi which will get its stdin from your keyboard device(the reader) by default, and another that provides remote access functionality over ssh. This way you can avoid having to deal with devices in /dev directly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.