Created
April 9, 2018 20:26
-
-
Save marianmoldovan/ab9869068a1c34880602f3fad25d175d to your computer and use it in GitHub Desktop.
HID Trinket M0 close tab and window hack
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
import digitalio | |
from board import * | |
import time | |
from adafruit_hid.keyboard import Keyboard | |
from adafruit_hid.keycode import Keycode | |
# the keyboard object! | |
kbd = Keyboard() | |
button = digitalio.DigitalInOut(D0) | |
button.direction = digitalio.Direction.INPUT | |
button.pull = digitalio.Pull.UP | |
def click(): | |
kbd.press(Keycode.GUI, Keycode.W) | |
kbd.release_all() | |
def long_click(): | |
kbd.press(Keycode.GUI, Keycode.Q) | |
kbd.release_all() | |
def loop(): | |
print("Waiting for button presses") | |
while True: | |
if (not button.value): # pressed? | |
first_click_time = time.monotonic() | |
while(not button.value): pass | |
click_time = time.monotonic() - first_click_time | |
if(click_time < 0.33): click() | |
elif(click_time < 1.3): long_click() | |
time.sleep(0.01) | |
loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment