Skip to content

Instantly share code, notes, and snippets.

@yetimdasturchi
Created July 1, 2022 21:37
Show Gist options
  • Save yetimdasturchi/8e4d48a8c2cbb62b19a7c9c1a492a4f0 to your computer and use it in GitHub Desktop.
Save yetimdasturchi/8e4d48a8c2cbb62b19a7c9c1a492a4f0 to your computer and use it in GitHub Desktop.
#include "PS2Mouse.h"
int clicked = 0;
a mouse(6,5); //clock, data
void setup(){
Serial.begin(9600);
while(!Serial);
mouse.begin();
}
void loop(){
uint8_t stat;
int x,y;
mouse.getPosition(stat,x,y);
if(stat==9){
clicked = 1;
}else{
clicked = 0;
}
Serial.print(x, DEC);
Serial.print(":");
Serial.print(y, DEC);
Serial.print(":");
Serial.println(clicked, DEC);
delay(50);
}
import pyautogui, sys, os, re, time, serial
pyautogui.FAILSAFE=False
ArduinoSerial=serial.Serial('/dev/USB0',9600, timeout=.1)
def isNotBlank (myString):
return bool(myString and myString.strip())
time.sleep(2)
while 1:
data=str(ArduinoSerial.readline().decode('ascii'))
print('c' + data)
if isNotBlank(data):
mous = re.match("(-?\d+):(-?\d+):(-?\d+)", data)
if mous:
result = [int(d) for d in re.findall(r'-?\d+', data)]
(X,Y)=pyautogui.position()
x=result[0]
y=result[1]
pyautogui.moveTo(X+x,Y-y)
if 1 == result[2]:
pyautogui.click(button="left")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment