Pc to Pc keyboard and mouse commands

Status
Not open for further replies.

Geosphere

New member
Hi all,

Sorry if this has been asked before or if it's something very simple todo and I'm just overthinking it,

The project I'm trying to make is to have a linux laptop send keyboard and mouse commands to to windows 10pc, i'm still trying to learn coding, but I have made a very simple python tkinter GUI with some buttons, when I press a button I want to send a command to the windows 10 PC via a USB to serial port adapter to serial1 on the Teensy 4.1 then usb cable to windows, commands i would like to use such as move mouse to X100 y100 click mouse or to simulate simple keyboard presses.

I could do this locally on the windows 10pc pretty easy with python, but I would like to automate it all from the laptop so no additional software is put on the win 10 pc, I'm just unsure what code/setup I should use on the teensy to act as a serial > HID, I have looked at the example code but I don't see how it can act as a keyboard and mouse, i guess tool>usb type adds additional code/setting i'm not seeing but even the example code I not sure what I really need.

I would appreciate any help.

Thanks,
Greg
 
Hi again

I have managed to get a basic code base working. I can send "100,100" and it will move the mouse x100 y100 from its current position, not really Ideal but I think I can work with it.


The problem I have at the moment is the keyboard. I can send a keystroke via serial but it will just echo so if I press A it will type A as it should, I would like to be able to use key press / release, maybe use something like.

if(Serial1.read() == 'a'){
keyboard.press ('a');

if(Serial1.read() == 'aa'){
keyboard.release ('a');

I'm sure I'm using it wrong as I can't seem to get it to work... and I guess it would be very ugly code. If you're able to give me a hint how I could convert the serial key to simulate a USB keyboard press it would be much appreciated.

Thanks
Greg
 
if(Serial1.available()) // if there is data comming
{
String command = Serial1.readStringUntil('\n'); // read string until meet newline character

if(command == "up")
{
Keyboard.press('w');
Serial1.println("Forward"); // send action to Serial Monitor
}

if(command == "stop")
{
Keyboard.releaseAll();
Serial1.println("Key is Released"); // send action to Serial Monitor
}


The above code seems to let me press and hold keys, and will also stop holding when I send "stop".

I really am starting to have fun trying to get my ugly hacked together code to work, slowly reading the code it all starts to make sens
 
Neat idea especially when the target PC does not enable its remote desktop support capability which is the most common way to control a Windows PC manually.

It looks like you've got the basic idea for keyboard emulation, so this comment is mostly about mouse pointer movement. All mice and many trackpads provide relative movement input, which would require knowing the pointer position before being able to point to a new location.

You may want to consider emulating a touchscreen, which should allow your emulator to provide absolute positioning of touch points. Most recent touchscreens also allow multiple contact points ("multitouch"), which may allow your emulator to be a bit more sophisticated in its control over the target PC.
 
Hi Len,

Thanks for the reply, I like the Idea of emulating a touch screen, but I can't seem to find how to do it. I can use Mouse.moveTo but I'm unsure how to send x y bytes via python...



I also find using "Serial1.readStringUntil('\n');" will really mess up the mouse move code I currently use as it will seem to skip move commands.

I changed to

int c = Serial1.read(); // note read() returns an int
if (c != -1) { // read() return -1 if there is nothing to be read.
// got a char handle it
Serial1.println((char)c); // need to cast to char c to print it otherwise you get a number instead
Keyboard.press((char)c);
delay (1000);
Keyboard.releaseAll();

but Its hard to emulate the button press length.


I really think I have bitten off more than I can chew with this project, I have never done any programming in arduino or in python I just wanted a nice long term project I could learn on, im just feel so inspired by all the amazing stuff people make and I can see so much potential in learning to code to also make cool stuff
 
Status
Not open for further replies.
Back
Top