Close Show/hide page

{zero point nine} personal experiments, etc.

Virtual Trackpad for Android

What started out as a quick test with sockets inevitably grew into a fully baked app.

I chose to create the desktop client in Java with the hope of being able to share the socket communications code between the desktop and Android clients. This actually worked out, without even a need for any platform-specific conditionals. A pleasant surprise to say the least.

Additionally, since both projects are Java based, I was able to stay in the same IDE (IntelliJ), which was nice. The desktop project uses SWT (a long-time Java UI library that uses OS-specific dependencies to allow for native OS-based UI widgets) and builds four different JAR's: Windows 32bit, Windows 64bit, OSX 32bit, and OSX 64bit (yikes). In the last step of the build process, a script packages the OSX versions into app bundles.

Cusor movement is done using the Java Robot class. You'll see that the mouse cursor can have "momentum" on-unpress, which in practice can be super-useful. And mouse acceleration is configurable using this one-liner which I need to remember to find uses for more often:

double logBase(double value, double base) { return log(value) / log(base); }

The network logic is hand-rolled, using UDP sockets. The size of the encoded messages are kept as small as humanly possible. For example, a mouse-move command uses only 20 bytes -- 4 bytes for a start-of-message token, 4 bytes for the command type (ie, move the mouse), two floats for the cursor position, and then 4 bytes for an end-of-message token. As a result, at least in my testing, under decent network conditions mouse-updating stays pegged at a steady 60hz.

View or post a comment