No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rfid_keypresser.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (C) 2011 Andrew Karpow <andy@mail.tu-berlin.de>
  5. # Licensed under GPL v3 or later
  6. from smartcard.CardMonitoring import CardMonitor, CardObserver
  7. from smartcard.util import toHexString
  8. from threading import Condition
  9. import subprocess
  10. # a simple card observer that prints inserted/removed cards
  11. class printobserver(CardObserver):
  12. def update(self, observable, (addedcards, removedcards)):
  13. for card in addedcards:
  14. SELECT_GUID= [0xFF, 0xCA, 0x00, 0x00, 0x00]
  15. print "+Inserted: ", toHexString(card.atr)
  16. try:
  17. card.connection = card.createConnection()
  18. card.connection.connect()
  19. # Request UID - Unique Identifier
  20. response, sw1, sw2 = card.connection.transmit(SELECT_GUID)
  21. except Exception as e:
  22. print str(e)
  23. continue
  24. # convert UID to hex-string and remove whitespaces
  25. send= toHexString(response).replace(' ', '')
  26. try:
  27. # Send UID to active window
  28. subprocess.Popen(['xdotool', 'type', send+'\n'])
  29. except OSError as e:
  30. print str(e)
  31. for card in removedcards:
  32. print "-Removed: ", toHexString(card.atr)
  33. if __name__ == '__main__':
  34. cardmonitor= CardMonitor()
  35. cardobserver= printobserver()
  36. cardmonitor.addObserver(cardobserver)
  37. try:
  38. c= Condition()
  39. c.acquire()
  40. c.wait()
  41. except KeyboardInterrupt as e:
  42. cardmonitor.deleteObserver(cardobserver)