Skip to content

Instantly share code, notes, and snippets.

@Keridos
Last active April 20, 2017 18:44
Show Gist options
  • Save Keridos/28fb408df82cae3b6b259e05f666b314 to your computer and use it in GitHub Desktop.
Save Keridos/28fb408df82cae3b6b259e05f666b314 to your computer and use it in GitHub Desktop.
from time import sleep
import keyboard
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
down = False
def onKeyboardDownEvent():
global down
if not down:
message = "down".encode("ascii")
s.sendto(message, remote)
down = True
def onKeyboardUpEvent():
global down
if down:
message = "up".encode("ascii")
s.sendto(message, remote)
down = False
remote = (socket.gethostbyname("keridos"), 12455)
keyboard.hook_key('f13', onKeyboardDownEvent, onKeyboardUpEvent)
try:
while True:
sleep(1)
finally:
print("error or quit")
keyboard.unhook_all()
import pyautogui
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
host = socket.gethostname()
port = 12455
s.bind((host, port))
try:
while True:
msg, addr = s.recvfrom(1024)
if msg.decode("ascii") == "down":
pyautogui.keyDown('scrolllock')
print("down")
elif msg.decode("ascii") == "up":
pyautogui.keyUp('scrolllock')
print("up")
finally:
s.shutdown(2)
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment