Share My Creation JVM KVM (RasPi, etc...) [open source]

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:
  • jAWTRobot
  • jColorLogger
  • jNativeHookB4J
  • jFileWatcher
The AsyncStreamsText class module has been heavily modified to include code for sending files (inspired by Erel's file transfer examples) as well as a few other tweaks.

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
place a batch file (just a plain text file with extension .bat) with the following content:
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
This should put you in GNU nano (a text editor) looking at the autostart file. Add
B4X:
@sh /home/pi/JVMKVMStartup.sh
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
B4X:
cd /home/pi
sudo nano JVMKVMStartup.sh
This will open up GNU nano with a new file. Type in the following contents:
B4X:
#!/bin/bash

sleep 60
lxterminal --working-directory=/home/pi/Downloads -e "java -jar JVMKVM_Target.jar"
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.
 

Attachments

  • JVMKVM_Controller.zip
    11.2 KB · Views: 477
  • JVMKVM_Target.zip
    4.8 KB · Views: 474
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
You should consider this a B4X community open source project. Feel free to tweak the code as you see fit. If you make interesting modifications to it, feel free (indeed, compelled) to post those modifications in this thread so that others may benefit. There's lots of room for improvement, so don't be shy. For example, the Controller doesn't do anything clever when it receives a file from the Target. Maybe you could show a system tray notification or something. The V part of KVM (Video) hasn't been added in, yet. I have it in other remote control projects that I've written but I haven't needed it for the RasPi2. If you have your own implementation, feel free to add it. If there's enough demand for it, I'll add my video implementation in.

The mouse mechanics are kind of sloppy right now; you aren't going to be playing Quake 3 on your RasPi2 with this set up. This is another area in which you could improve this project. Note that the jNativeHookB4J library has event consumption, which might play a role in a new, more responsive mouse mode.

You could also make Android or iOS versions of the Controller app, if you were so inclined.
 
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
Glad you enjoy it. Feel free to share any code tweaks or additions you make to the project. This project has significant room for improvement.
 
Top