Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import RPi.GPIO as gpio
- from time import sleep
- from evdev import uinput, ecodes as e
- gpio.setmode(gpio.BCM)
- gpio.setup(2, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(3, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(4, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(5, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(6, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(7, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(8, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(9, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(10, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(11, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(12, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(13, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(14, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(15, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(16, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(17, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(18, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(19, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(20, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(21, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(22, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(23, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(24, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(25, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(26, gpio.IN, pull_up_down = gpio.PUD_UP)
- gpio.setup(27, gpio.IN, pull_up_down = gpio.PUD_UP)
- p1up = 2
- p1down = 3
- p1left = 4
- p1right = 5
- p1b1 = 6
- p1b2 = 7
- btstart = 8
- btselect = 9
- p2up = 10
- p2down = 11
- p2left = 12
- p2right = 13
- p2b1 = 14
- p2b2 = 15
- btexit = 16
- p1coin = 17
- p2coin = 18
- p1start = 19
- p2start = 20
- l = 21
- r = 22
- x = 23
- y = 24
- p1b3 = 25
- p2b3 = 26
- def p1uppress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_UP, 1)
- ui.write(e.EV_KEY, e.KEY_UP, 0)
- ui.syn()
- while gpio.input(p1up) == False:
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_UP, 1)
- ui.write(e.EV_KEY, e.KEY_UP, 0)
- ui.syn()
- def p1downpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_DOWN, 1)
- ui.write(e.EV_KEY, e.KEY_DOWN, 0)
- ui.syn()
- while gpio.input(p1down) == False:
- ui.write(e.EV_KEY, e.KEY_DOWN, 1)
- ui.write(e.EV_KEY, e.KEY_DOWN, 0)
- ui.syn()
- def p1leftpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_LEFT, 1)
- ui.write(e.EV_KEY, e.KEY_LEFT, 0)
- ui.syn()
- while gpio.input(p1left) == False:
- ui.write(e.EV_KEY, e.KEY_LEFT, 1)
- ui.write(e.EV_KEY, e.KEY_LEFT, 0)
- ui.syn()
- def p1rightpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_RIGHT, 1)
- ui.write(e.EV_KEY, e.KEY_RIGHT, 0)
- ui.syn()
- while gpio.input(p1right) == False:
- ui.write(e.EV_KEY, e.KEY_RIGHT, 1)
- ui.write(e.EV_KEY, e.KEY_RIGHT, 0)
- ui.syn()
- def p1b1press(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_LEFTCTRL, 1)
- ui.write(e.EV_KEY, e.KEY_LEFTCTRL, 0)
- ui.syn()
- def p1b2press(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_LEFTALT, 1)
- ui.write(e.EV_KEY, e.KEY_LEFTALT, 0)
- ui.syn()
- def p1b3press(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_SPACE, 1)
- ui.write(e.EV_KEY, e.KEY_SPACE, 0)
- ui.syn()
- def btstartpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_ENTER, 1)
- ui.write(e.EV_KEY, e.KEY_ENTER, 0)
- ui.syn()
- def btselectpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_RIGHTSHIFT, 1)
- ui.write(e.EV_KEY, e.KEY_RIGHTSHIFT, 0)
- ui.syn()
- def btexitpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_ESC, 1)
- ui.syn()
- sleep(0.125)
- ui.write(e.EV_KEY, e.KEY_ESC, 0)
- ui.syn()
- sleep(0.125)
- ui.write(e.EV_KEY, e.KEY_F12, 1)
- ui.write(e.EV_KEY, e.KEY_ENTER, 1)
- ui.syn()
- sleep(0.25)
- ui.write(e.EV_KEY, e.KEY_F12, 0)
- ui.write(e.EV_KEY, e.KEY_ENTER, 0)
- ui.syn()
- def lpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_Q, 1)
- ui.write(e.EV_KEY, e.KEY_Q, 0)
- ui.syn()
- def rpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_W, 1)
- ui.write(e.EV_KEY, e.KEY_W, 0)
- ui.syn()
- def xpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_I, 1)
- ui.write(e.EV_KEY, e.KEY_I, 0)
- ui.syn()
- def ypress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_O, 1)
- ui.write(e.EV_KEY, e.KEY_O, 0)
- ui.syn()
- def p1coinpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_5, 1)
- ui.write(e.EV_KEY, e.KEY_5, 0)
- ui.syn()
- def p2coinpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_6, 1)
- ui.write(e.EV_KEY, e.KEY_6, 0)
- ui.syn()
- def p1startpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_1, 1)
- ui.write(e.EV_KEY, e.KEY_1, 0)
- ui.syn()
- def p2startpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_2, 1)
- ui.write(e.EV_KEY, e.KEY_2, 0)
- ui.syn()
- def p2uppress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_R, 1)
- ui.write(e.EV_KEY, e.KEY_R, 0)
- ui.syn()
- def p2downpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_F, 1)
- ui.write(e.EV_KEY, e.KEY_F, 0)
- ui.syn()
- def p2leftpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_D, 1)
- ui.write(e.EV_KEY, e.KEY_D, 0)
- ui.syn()
- def p2rightpress(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_G, 1)
- ui.write(e.EV_KEY, e.KEY_G, 0)
- ui.syn()
- def p2b1press(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_A, 1)
- ui.write(e.EV_KEY, e.KEY_A, 0)
- ui.syn()
- def p2b2press(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_S, 1)
- ui.write(e.EV_KEY, e.KEY_S, 0)
- ui.syn()
- def p2b3press(channel):
- with uinput.UInput() as ui:
- ui.write(e.EV_KEY, e.KEY_Q, 1)
- ui.write(e.EV_KEY, e.KEY_Q, 0)
- ui.syn()
- gpio.add_event_detect(p1up, gpio.RISING, callback=p1uppress)
- gpio.add_event_detect(p1down, gpio.RISING, callback=p1downpress)
- gpio.add_event_detect(p1left, gpio.RISING, callback=p1leftpress)
- gpio.add_event_detect(p1right, gpio.RISING, callback=p1rightpress)
- gpio.add_event_detect(p1b1, gpio.RISING, callback=p1b1press)
- gpio.add_event_detect(p1b2, gpio.RISING, callback=p1b2press)
- gpio.add_event_detect(p1b3, gpio.RISING, callback=p1b3press)
- gpio.add_event_detect(btstart, gpio.RISING, callback=btstartpress)
- gpio.add_event_detect(btselect, gpio.RISING, callback=btselectpress)
- gpio.add_event_detect(btexit, gpio.RISING, callback=btexitpress)
- gpio.add_event_detect(l, gpio.RISING, callback=lpress)
- gpio.add_event_detect(r, gpio.RISING, callback=rpress)
- gpio.add_event_detect(x, gpio.RISING, callback=xpress)
- gpio.add_event_detect(y, gpio.RISING, callback=ypress)
- gpio.add_event_detect(p1coin, gpio.RISING, callback=p1coinpress)
- gpio.add_event_detect(p2coin, gpio.RISING, callback=p2coinpress)
- gpio.add_event_detect(p1start, gpio.RISING, callback=p1startpress)
- gpio.add_event_detect(p2start, gpio.RISING, callback=p2startpress)
- gpio.add_event_detect(p2up, gpio.RISING, callback=p2uppress)
- gpio.add_event_detect(p2down, gpio.RISING, callback=p2downpress)
- gpio.add_event_detect(p2left, gpio.RISING, callback=p2leftpress)
- gpio.add_event_detect(p2right, gpio.RISING, callback=p2rightpress)
- gpio.add_event_detect(p2b1, gpio.RISING, callback=p2b1press)
- gpio.add_event_detect(p2b3, gpio.RISING, callback=p2b2press)
- gpio.add_event_detect(p2b3, gpio.RISING, callback=p2b3press)
- while True:
- sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement