Created
April 9, 2016 19:28
-
-
Save marceloslacerda/15ff6c7268d7a6e1354d7f944e49405e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen, PIPE | |
TOP_LEFT = '00,00,00,00,00,01,00,11,01,01,00,00,00' | |
BOT_LEFT = '00,00,00,00,00,01,00,10,01,01,00,00,00' | |
TOP_RIGT = '00,00,00,00,00,01,00,15,01,01,00,00,00' | |
BOT_RIGT = '00,00,00,00,00,01,00,16,01,01,00,00,00' | |
END = '00,00,00,00,00,00,00,00,00,00,00,00,00' | |
A = '''keydown Control_L | |
key z | |
keyup Control_L | |
''' | |
B = '''keydown Control_L | |
key r | |
keyup Control_L | |
''' | |
C = '''keydown Control_L | |
key w | |
keyup Control_L | |
''' | |
D = '''keydown Control_L | |
key u | |
keyup Control_L | |
''' | |
def keypress(sequence): | |
p = Popen(['xte'], stdin=PIPE) | |
p.communicate(input=bytes(sequence, 'utf-8')) | |
def process_wacom(): | |
with open('/dev/input/by-id/usb-Wacom_Co._Ltd._Intuos_PS-event-if01', 'rb') as input: | |
array = '' | |
while True: | |
byte = input.read(1) | |
array += ',{0:02x}'.format(byte[0]) | |
if array.endswith(END): | |
print(array) | |
if TOP_LEFT in array: | |
print('TOP LEFT') | |
keypress(A) | |
if BOT_LEFT in array: | |
print('BOTTOM LEFT') | |
keypress(B) | |
if TOP_RIGT in array: | |
print('TOP RIGHT') | |
keypress(C) | |
if BOT_RIGT in array: | |
print('BOTTOM RIGHT') | |
keypress(D) | |
array = '' | |
if __name__ == '__main__': | |
print('Starting redirection') | |
try: | |
process_wacom() | |
except IOError: | |
print('Tablet is not available...') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment