RFID: Add current Keypresser Code

This commit is contained in:
Andy 2011-10-18 00:22:30 +02:00 committed by Sebastian Pipping
parent f5d40285a1
commit 7c8a072f4f
1 changed files with 55 additions and 0 deletions

55
rfid/rfid_keypresser.py Executable file
View File

@ -0,0 +1,55 @@
#! /usr/bin/env python
# by Andrew Karpow <andy@mail.tu-berlin.de>
# Public Domain
from smartcard.CardMonitoring import CardMonitor, CardObserver
from smartcard.util import toHexString
from threading import Condition
import subprocess
# a simple card observer that prints inserted/removed cards
class printobserver(CardObserver):
def update(self, observable, (addedcards, removedcards)):
for card in addedcards:
SELECT_GUID= [0xFF, 0xCA, 0x00, 0x00, 0x00]
print "+Inserted: ", toHexString(card.atr)
try:
card.connection = card.createConnection()
card.connection.connect()
# Request UID - Unique Identifier
response, sw1, sw2 = card.connection.transmit(SELECT_GUID)
except Exception as e:
print str(e)
continue
# convert UID to hex-string and remove whitespaces
send= toHexString(response).replace(' ', '')
try:
# Send UID to active window
subprocess.Popen(['xdotool', 'type', send])
except OSError as e:
print str(e)
for card in removedcards:
print "-Removed: ", toHexString(card.atr)
if __name__ == '__main__':
cardmonitor= CardMonitor()
cardobserver= printobserver()
cardmonitor.addObserver(cardobserver)
try:
c= Condition()
c.acquire()
c.wait()
except KeyboardInterrupt as e:
cardmonitor.deleteObserver(cardobserver)