⬆️ ⬇️

Touchpad and keyboard from the handy device on Windows Mobile

Do you have a communicator with WM and the need to control your PC with it?



Maybe you want to spend some tricky presentation that requires a mouse in your pocket?

image



Ok, you need a cat (there are pictures).

')

If you are only interested in the final product, but not technical details, I recommend not to go to the FAQ section without stopping.



Concept



Task: Turn the WM-communicator into a full-fledged touchpad and keyboard, and at the same time gain the ability to control any win-system with its help.

In general, a managed system may not be win, but more on that below.

As a transport, we will use UDP / IP over Wi-Fi, or (for connoisseurs) Bluetooth.

What is required for this:In order, the client part is



WM application



Written under the .NET Compact Framework 3.5 on C # , tested on HTC HD2 with WM 6.5 .

The client application does not use any vendor-specific API, so it should work on all devices with WM 5 and 6.

The principle of capturing input from the keyboard and touchscreen is extremely simple:
  1. Create some kind of control, and stretch it to fit the window (Dock = Fill);
  2. We put a focus on him;
  3. Subscribe to KeyDown, KeyUp, KeyPress events to intercept keystrokes;
  4. MouseDown, MouseUp, MouseMove for touchpad emulation.


Touchpad


A little about the terms in which the principle of touchpad emulation is expressed - they are used in the further description:The touchpad logic is implemented in the MouseHandler class, here it is:

image

ConfigApply and ConfigStore are irrelevant; All MouseHandler work comes down to handling its events, whose purpose as a whole is clear from the names.



Keyboard


The device is trivial:

image

Developments:
Customer


Class whose task is to generate control messages for sending to the server:

image

We get the requested action through a method of the type KeyboardCommand (), MouseMove (), etc; form the message, send it to the socket via the OnPacketSend event.



Configs


The user is presented with a unique opportunity to edit their configs in the root XML format.

How the application implements work with them, see for yourself if anyone is interested. I do not want to talk about it.

image



Screen:

image



The purpose of the main configs fields, which is not obvious from the name:
Interface


When drawing the interface, I was inspired by the popular picture of Kazimir Malevich:

image image

Since the GUI is considered to be a self-documenting user interface, I still left button labels (screen on the left), which disappear after the first touch of the touchpad (screen on the right).

Yes, I have not said: this black field on the screen is the touchpad; the purpose of the buttons should be obvious from their name. Using the keyboard, too, should not cause questions.

The portrait orientation of the window is used to save screen space for the touchpad; at the same time the use of the touchpad itself is assumed in the landscape (but it is customizable).



Server



The first attempt to create a more or less cross-platform server using python and SendKeys failed because it turned out that SendKeys does not know Unicode. How to work from a python with a mouse, I did not even look.

The second attempt (successful) was using WinAPI from a console application in C, where the work of writing commands to the mouse and keyboard stream is performed using the SendInput function.

A simple console application that listens to a UDP socket and periodically calls SendInput () is not worth considering. I note only that it practically does not consume system resources (especially when the client is disabled), so that it can be kept running all the time.



As far as portability is concerned, it is not difficult to write a platform-specific application for any other platform (the audience would need it), since a simple to implement command is used to deliver commands to the managed system



Protocol



Data is transmitted only from the client to the server, no confirmation or return commands are provided.

Any command is sent in a fixed-size frame consisting of the following fields:Default port 12358 (selection prompted by a sequence fragment).



FAQ



Q: Ok, I want to use Device2Keyboard. What do I need to do for this?

A: Download the client and server application on the links at the end of the post, and run them. The default settings assume that the communicator and the server must be on the same subnet, since the client has the default server address 255.255.255.255:12358 (broadcast IP address). Everything will work out of the box, no additional configuration is required.



Q: I do not want to use wireless interfaces. How to be?

A: Connect the communicator to a managed PC with ActiveSync installed, leaving the default client settings. Everything will work.



Q: I fixed a click by executing Drag'n'Drop, but the connection to the server was interrupted, and the click remained clamped. What to do?

A: Wait 3 seconds. If the server does not receive a command to set the state of mouse clicks from the client during this time, it will release all held buttons.



Q: When the mouse cursor is moved for a long time, my network will fall down due to the terrible traffic, right?

A: The default frequency of updating the cursor position is 10 ms (100 times per second); packet size (3 + 1 + 1 + 4) == 9 bytes, + overhead UDP / IP frame 28 bytes, we get 37 bytes in 1 message, or 3.6 kbit / s. If the mouse does not move, its position is not updated. The answer is negative.



Conclusion



Application for WM and desktop, installation do not require: dl.dropbox.com/u/3815390/dev2kbd/bin/bin.7z

Sources: dl.dropbox.com/u/3815390/dev2kbd/src/src.7z

The application and its sources are distributed under the WTFPL license.

Photo from the title, source: migdal-or.livejournal.com/55703.html

Source: https://habr.com/ru/post/120247/



All Articles