simulating keystroke on the remote machine you sshed to
Pre
Assuming you have a machine connected to a monitor or television as a movie player, and the tv maybe keep a distance from you since you wouldn’t like to watch movies so close to it.
Issue
The machine is away from you which make it inconvenient to control it.
- Physical way: connect a keyboard with long wire or a wireless bluetooth one. For mouse, options are few here, a wireless one should be great.
- Remote way: use another machine to control it.
Since I don’t have a wireless keyboard, I’d like to try the remote way.
Also I don’t want a keyboard lie besides my pillow, but I can bear a computer though since I have to use it anyway.
It’s easy to imageine that there’re some softwares focusing on solving this kind of problem by control mouse and keyboard input remotely.
However they’re almost all gui based tools, which is unfriendly for me, because I’d like to work in a pure tty with archlinux or something.
So I have to make it work on my own.
Solution
- Ssh into the remote machine,
- Read the keyboard input
- Since the remote one is a macbook, I have to execute osascript to simulate keyboard keystroke according to the input read from terminal.
We achieve this by writing a script to receive the input and convert it into a osascript.
When you want to simulate the keyboard input, execute the script.
flowchart LR
subgraph B[By side Machine]
t(tty)
end
t -.- |ssh| T
t --> |input| s
subgraph R[Remote Machie]
subgraph T[terminal]
s(sh script)
end
s --> o(osascript)
o --> k
subgraph k[simulate keyboard]
end
end
Source
This is a very basic and rough one, you should edit it to make it work better.
1 |
|