availability: January 2017
I have been experimenting with sending VNC keystrokes in different ways before . To finalize these experiments I decided to create a java library that is able to send keys towards a vnc server. I take advantage of existing logic of the vnc-tight project.
The project provides the source for a java based vncviewer, but the problem is that it uses an applet awt-based interface. I wanted it to be used from the commandline without the X requirement.
The commandline version
<% codify(:shell) do %>
usage: java -jar jvncsender.jar [-list] [-help] -host
text can also take special keys f.i. like "linux ks=ks.cfg
or from within java:
<% codify(:java) do %>
try {
VncSender vncSender=new VncSender(vncHost,vncPort,vncPassword);
vncSender.setVncWaitTime(timeInSec);
vncSender.sendText(vncText);
} catch (Exception ex) { System.out.println(ex.toString()); } <% end %>
I've been using it for automating kickstarts via VNC vmware.
F.i. my text string for kickstarting an ubuntu server without creating a custom cdrom would look like this:
<% codify(:java) do %>
vncText=new String[]{ "
Note: this only works if your keyboard mapping is in us mode, as the keymappings are scancodes not actual ascii codes.
<% codify(:shell) do %>
$ svn co https://vnc-tight.svn.sourceforge.net/svnroot/vnc-tight vnc-tight
$ svn co https://vnc-tight.svn.sourceforge.net/svnroot/vnc-tight/trunk/java vnc-tight-java <% end %>
I ended up using the jar file announced TightVNC: VNC Viewer with SSH Tunneling - April 2010
In order to get access to certain functions, I put my classes inside the same package. But because the jar file was signed, I needed to remove the signing:
<% codify(:shell) do %> $ wget http://www.tightvnc.com/download/tightvnc-1.5.1-jviewer-bin.zip $ unzip tightvnc-1.5.1-jviewer-bin.zip $ cd tightvnc-1.5.1-jviewer-bin $ ls *.jar TightVncViewer.jar $ mkdir newjar $ cd newjar $ jar -xvf ../TightVncViewer.jar $ rm -rf META-INF $ jar -cvf TighTVncViewer-unsigned.jar <% end %>