pi-as-keyboard
pi-as-keyboard copied to clipboard
Set the mouse to a position
Is it possible to set the mouse to a defined x,y position on the display?
Hi,
Sorry for the delay. It should be possible ! I will test it and update the project / issue.
I have added a c program to this repo « to play » with HID code. I will try some combination this week-end.
With the test script I was able to click, but not moving the cursor on OSX.
I will try on another computer this weekend
Thanks so far. A click on a defined position would be great. I use it on linux at the moment and I move cursor with the number keypad (for example the 8 to move the cursor to the north). I make a click with the enter key on the keypad. This workes but it would be better to set the cursor to position x,y. It would be faster and much more exakt.
According the documentation the position should be in percentage since the HID device didn't have any clue of the resolution of your monitor.
Example :
- 0,0 is the top left
- 100,100 is the bottom right
My python script looks like this at the moment.
#!/usr/bin/python
import time
def write_report(report):
with open('/dev/hidg0', 'rb+') as fd:
fd.write(report.encode())
NULL_CHAR = chr(0)
write_report(NULL_CHAR*2+chr(0x5F)+NULL_CHAR*5) # go to north west with KEYPAD_7
time.sleep(2.2)
write_report(NULL_CHAR*8)
I go from the current mouse position to the left top corner. What do I have to change to make the mouse position for example in the middle (50,50)?
You find the solution here: https://github.com/pelya/android-keyboard-gadget/issues/135#issuecomment-386842277
Worked for me!