Advertisement
metalx1000

Card Scanner and other HID background reader - RFID

Jun 27th, 2018
1,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Copyright Kris Occhipinti
  4. # June 27th 2018
  5. # https://filmsbykris.com
  6. # Licensed under the GPLv3
  7. # https://www.gnu.org/licenses/gpl-3.0.txt
  8. #    
  9. # Allows normal HID Keyboard like device to be read in background
  10. # Install needed files
  11. # sudo apt install xinput python-evdev
  12. #
  13. # Disable device as HID in Xorg (Sycreader in my exmaple)
  14. # xinput --disable "$(xinput|grep "Sycreader RFID Technology"|cut -d\= -f2|awk '{print $1}')"
  15. #
  16. # You will probably want to make the device readable rather then run this script as root
  17. # sudo chmod +r /dev/input/by-id/usb-Sycreader_RFID_Technology_Co.__Ltd_SYC_ID_IC_USB_Reader_08FF20140315-event-kbd
  18. # (again Sycreader_RFID is my device change to your device
  19.  
  20. import os
  21. from evdev import InputDevice, categorize, ecodes
  22.  
  23. output = ""
  24.  
  25. #set your device
  26. dev = "/dev/input/by-id/usb-Sycreader_RFID_Technology_Co.__Ltd_SYC_ID_IC_USB_Reader_08FF20140315-event-kbd"
  27. device = InputDevice(dev) # my keyboard
  28.        
  29. #check list of codes and run command if cound
  30. def find_command(code):
  31.     for line in open("codes.lst"):
  32.         if code in line:
  33.             command = line.split("|")[1].rstrip("\n\r") + " &"
  34.             print(command)
  35.             os.system(command)
  36.  
  37. #main loop
  38. for event in device.read_loop():
  39.     if event.type == ecodes.EV_KEY & event.value == 1:
  40.         #print(categorize(event))
  41.         # 28 is enter key.
  42.         #so when "Enter" is pressed
  43.         if event.code == 28:
  44.             print(output)
  45.             find_command(output)
  46. #            if output == "2267233788":
  47. #                os.system("/usr/games/minetest &")
  48.             #clear Variable
  49.             output = ""
  50.         else:
  51.             #if "Enter" is not pressed add last value to string
  52.             output += str(event.code)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement