Skip to content

Instantly share code, notes, and snippets.

@will-h
Created March 31, 2018 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save will-h/ef90dbb16b98547d3c28913262243e41 to your computer and use it in GitHub Desktop.
Save will-h/ef90dbb16b98547d3c28913262243e41 to your computer and use it in GitHub Desktop.
hacky thing to switch chrome tabs based on GPIO on rasppi
#!/usr/bin/python
#!/usr/bin/python
#!/usr/bin/python
import time
import RPi.GPIO as GPIO
from xdo import Xdo
xdo = Xdo(display=":0.0")
GPIO.setmode(GPIO.BCM)
GPIO.setup(2, GPIO.IN)
#, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(3, GPIO.IN)
#, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(2, GPIO.RISING)
GPIO.add_event_detect(3, GPIO.RISING)
def my_callback(pin):
if pin == 2:
key = "ctrl+Prior"
elif pin == 3:
key = "ctrl+Next"
else:
print "unknown pin: ", pin
return
#print pin, key, 'PUSHED!'
win_id = xdo.get_focused_window()
xdo.send_keysequence_window(win_id, key)
GPIO.add_event_callback(2, my_callback)
GPIO.add_event_callback(3, my_callback)
while True:
time.sleep(2)
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment