This is two-thirds of a full KVM that runs in the JVM. There are two components: the JVMKVM_Controller and the JVMKVM_Target. You run the target on the machine you want to control. You run the controller on the machine that will be doing the controlling. I've been using it to control a RasPi2 with the keyboard and mouse on my development computer. That's right; rather than spend 12 seconds unplugging my keyboard/mouse and plugging them into the RasPi2, I spent numerous hours writing programs to do it for me.
Features and Usage
The usage is as follows. JVMKVM_Target.jar is a non-UI B4J app. Run it from a terminal emulator or command line window on the target machine (RasPi2 in my case, but it's cross-platform). It will display the machine's local IP address and a port number. Then, on the controlling machine, run the JVMKVM_Controller.jar. It is a JavaFX B4J app. I recommend running it in the B4J IDE at first so you can see the logs and tweak the code as you wish.
In the Controller app, start the NativeHookListener by pressing the button so labeled. Then type in the target machine's local IP address and port number in the indicated text field. Then press the "Connect" button. Then, when you want your keyboard/mouse input to be transmitted to the target machine, press the "Transmit" button. There are 3 mouse modes: Off, Raw and MousePad. Raw transmits raw mouse clicks and raw mouse movements as they pass through the MainForm's window. MousePad mode transmits your click-and-drag mouse movements on the mouse pad panel as if it was a laptop's track pad. Transmitting clicks is done by clicking on the indicated buttons below the mouse pad panel. Changing mouse modes is performed by clicking on the label that displays the mouse mode or pressing ctrl_f2.
You can send files back and forth between the Target and Controller. That process is pretty self-explanatory from within the apps. Stopping the JVMKVM_Target.jar can be done a few different ways. If it's running in a terminal emulator, closing that window will end the program. You can also type in "exit" on the command line. Lastly, you can delete a file the program places on the desktop. It's best to use either of the two last methods as these allow resources to be properly released before the program closes. Note that the self-restarting functionality is Windows-only, for now. jAWTRobot will eventually be updated to make it cross-platform.
Libraries and Classes
In order to use these apps, you'll need some non-standard libraries that someone, through excessive generosity, has posted:
Auto-startup Windows
If your target machine doesn't have an attached keyboard and mouse, you face a chicken-and-the-egg paradox. How to start the JVMKVM_Target.jar without a keyboard/mouse? But that jar is supposed to provide keyboard/mouse functionality! The solution is to have JVMKVM_Target.jar run on system startup. In Windows, this is easy. In
place a batch file (just a plain text file with extension .bat) with the following content:
Auto-startup Raspbian NOOBS
In Raspbian via NOOBS, this is somewhat more involved. Open an LXTerminal session and type in
This should put you in GNU nano (a text editor) looking at the autostart file. Add
to the end of the file (it should be on the last line, by itself). Then press ctrl_x, y and enter to exit nano and save the changes. Then, type
This will open up GNU nano with a new file. Type in the following contents:
Then exit and save as before. Don't forget to make this file executable and then place JVMKVM_Target.jar in /home/pi/Downloads. Now, whenever your RasPi2 logs into Raspbian, it will wait for 60 seconds and then open an LXTerminal session and automatically start the JVMKVM_Target.jar inside it.
Features and Usage
The usage is as follows. JVMKVM_Target.jar is a non-UI B4J app. Run it from a terminal emulator or command line window on the target machine (RasPi2 in my case, but it's cross-platform). It will display the machine's local IP address and a port number. Then, on the controlling machine, run the JVMKVM_Controller.jar. It is a JavaFX B4J app. I recommend running it in the B4J IDE at first so you can see the logs and tweak the code as you wish.
In the Controller app, start the NativeHookListener by pressing the button so labeled. Then type in the target machine's local IP address and port number in the indicated text field. Then press the "Connect" button. Then, when you want your keyboard/mouse input to be transmitted to the target machine, press the "Transmit" button. There are 3 mouse modes: Off, Raw and MousePad. Raw transmits raw mouse clicks and raw mouse movements as they pass through the MainForm's window. MousePad mode transmits your click-and-drag mouse movements on the mouse pad panel as if it was a laptop's track pad. Transmitting clicks is done by clicking on the indicated buttons below the mouse pad panel. Changing mouse modes is performed by clicking on the label that displays the mouse mode or pressing ctrl_f2.
You can send files back and forth between the Target and Controller. That process is pretty self-explanatory from within the apps. Stopping the JVMKVM_Target.jar can be done a few different ways. If it's running in a terminal emulator, closing that window will end the program. You can also type in "exit" on the command line. Lastly, you can delete a file the program places on the desktop. It's best to use either of the two last methods as these allow resources to be properly released before the program closes. Note that the self-restarting functionality is Windows-only, for now. jAWTRobot will eventually be updated to make it cross-platform.
Libraries and Classes
In order to use these apps, you'll need some non-standard libraries that someone, through excessive generosity, has posted:
- jAWTRobot
- jColorLogger
- jNativeHookB4J
- jFileWatcher
Auto-startup Windows
If your target machine doesn't have an attached keyboard and mouse, you face a chicken-and-the-egg paradox. How to start the JVMKVM_Target.jar without a keyboard/mouse? But that jar is supposed to provide keyboard/mouse functionality! The solution is to have JVMKVM_Target.jar run on system startup. In Windows, this is easy. In
B4X:
C:\Users\<USERNAME>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
B4X:
cd C:\Path\To\JVMKVMProject\Objects
java -jar JVMKVM_Target.jar
Auto-startup Raspbian NOOBS
In Raspbian via NOOBS, this is somewhat more involved. Open an LXTerminal session and type in
B4X:
cd /home/pi/.config/lxsession/LXDE-pi
sudo nano autostart
B4X:
@sh /home/pi/JVMKVMStartup.sh
B4X:
cd /home/pi
sudo nano JVMKVMStartup.sh
B4X:
#!/bin/bash
sleep 60
lxterminal --working-directory=/home/pi/Downloads -e "java -jar JVMKVM_Target.jar"
Attachments
Last edited: