Using USB Keyboard

So, instead of going for a dictionary, I went for a dirty, manual method of if statements. This is the finished version of the code:

#!/usr/bin/python -u
# Note -u parameter above, which makes this script run in ubuffered mode
import struct
import time
import sys

# This script expects one argument, the event id number.

# default values
infile_path = "/dev/input/event1"


#long int, long int, unsigned short, unsigned short, unsigned int
FORMAT = 'llHHI'
EVENT_SIZE = struct.calcsize(FORMAT)


#open file in binary mode
in_file = open(infile_path, "rb")

event = in_file.read(EVENT_SIZE)

while event:
    (tv_sec, tv_usec, type, code, value) = struct.unpack(FORMAT, event)

    if type == 1 and value == 1:

#if type == 1 and value == 1:
 	        if code == 71:
                print 7
	        if code == 72:
                print 8   
  	      if code == 73:
                print 9   
          if code == 75:
                print 4 
          if code == 76:
                print 5 
          if code == 77:
                print 6 
          if code == 79:
                print 1 
          if code == 80:
                print 2 
          if code == 81:
                print 3
          if code == 82:
                print 0 
          if code == 83:
                print 'a' 
          if code == 96:
                print 'b' 
   	      if code == 14:
                print 'c'
   	      if code == 78:
                print 'd' 
   	      if code == 74:
                print 'e' 
   	      if code == 55:
                print 'f' 
   	      if code == 98:
                print 'g'  



    event = in_file.read(EVENT_SIZE)

in_file.close()

The process is very responsive, and since I will not be pressing more than one key every now and then(I'm building a midi controller) I don't see a reason to go different route, even though I would learn how to use a dictionary and-I guess-have a more streamlined code.

In the arduino side everything looks good as well, this is the test code that will be incorporated-with the necessary changes in my main sketch(minus there serial.print, it's here only for testing purposes):

#include <Bridge.h>
#include <Process.h>

Process p;

void setup()
{
   Bridge.begin();
   Serial.begin(19200);
   
   p.begin("/mnt/sda1/numpad.py");
   p.runAsynchronously(); 
}

void loop()
{
     
   
   while (p.available()){
     if ((char)p.read() == '1'){
       //Serial.print((char)p.read());
       Serial.println("hello");

      }

  }    

}

You will notice that right now only key 1 produces results, that's because I was testing how to assign each button to execute a specific part of the code, and-guess what- again I'm gonna use ifs for every case. I might try to find out how to setup an array(I guess?) to do this instead of 18 if statements(btw, are they more taxing for the processor?).

Is there any way to get values from numeric keys when numlock is off? Now I don't get anything nor could I find a way.

One last question. One of the keys in the numpad is a triple 0, that is, if pressed, it will send 3 zeros one after the other. I'd like to be able to use it as well, without delaying the loop. My guess is I'll have to do it on linux side, something like, if code == 0, wait for 5ms, if within those 5 ms you didn't get more zeros, print 0, if you did, print 'h'. Is it a sound way to do it?