Git Product home page Git Product logo

desktopkeyboard2android's Introduction

DesktopKeyboard2Android

Use your laptop's keyboard for typing in your Android phone

WifiKeyboard is a great android app that lets you use your laptop's keyboard to type into your android. You connect your laptop and android together by wifi or usb. In your laptop, you use a web browser, "the client", to type into your android.

This project replaces "the client", while still using the android app. The differences are:

  • The client is a standalone software, instead of a web page
  • There are not parameters to set-up (so, no interaction with the application needed)
  • It works with non-US keyboards (eg, accents) while it also forwards combination keys. So for example, you can copy a text from an android app and paste it to another app by using Crt-C & Crtl-V (as if the keyboard was attached directly to the phone, without a laptop being present)

Use

  • Install the WifiKeyboard app
  • Follow its instructions to connect your laptop and android together through wifi or usb. This includes executing from the terminal: adb forward tcp:7777 tcp:7777
  • Test that it works by browsing this web page from your laptop and type some text: http://localhost:7777/
  • Install and run the latest release of DesktopKeyboard2Android
  • What you type now in your laptop, it will be forwarded to your Android

You may want to use a hot key (eg Alt+Cmd+X) to launch or re-activate both the adb forward command and DesktopKeyboard2Android. Follow the instructions for OSX, MsWindows or Linux.

Compile

Retrieve source code

$ git clone https://github.com/dportabella/DesktopKeyboard2Android.git
$ cd DesktopKeyboard2Android

Execute from source code

To debug this application:

$ mvn exec:java -Dexec.mainClass="desktopKeyboard2Android.DesktopKeyboard2Android"

To show the java key events and understand how they are filtered and mapped for Android:

$ mvn exec:java -Dexec.mainClass="desktopKeyboard2Android.ShowJavaKeyEvents"

Build a native installer

$ mvn jfx:native

Java Multi-OS executable

$ java -jar target/jfx/app/DesktopKeyboard2Android-1.1-SNAPSHOT-jfx.jar

Linux Debian/Ubuntu package

Install the Debian package:

$ sudo dpkg -i target/jfx/native/desktopkeyboard2android-1.1.deb

Start from command line:

$ /opt/DesktopKeyboard2Android/DesktopKeyboard2Android

Start from Unity launcher: search for "DesktopKeyboard2Android" (it's case insensitive).

Start from other desktop: the application is installed under "All Applications" or "Unknown" category.

There is a desktop starter available in /opt/DesktopKeyboard2Android/DesktopKeyboard2Android.desktop. If you copy it to ~/Desktop/ or ~/.local/share/applications/, then you should edit it to add Hidden=false. You can also drag n' drop from nautilus to the Unity bar.

Windows

For creating the installer on MsWindows, you may need to download and install “Inno Setup 5” or later, see the output of the previous command. No requirements for OSX.

Todo

  • Replace the GUI window by a system tray icon
  • Remove the need to first run the adb command
  • Put the key events in a queue, instead of blocking the application

Notes for developers

Java produces three types of events when typing text: KeyPressed, KeyTyped and KeyReleased. KeyPressed and KeyRelease have information about the key code, and it always corresponds to a single key. KeyTyped is generated by the operating system according to the keyboard layout configuration (eg, a US keyboard or Swiss-French keyboard). It may require to type several keys before getting a KeyTyped event. For instance, typing the 'Alt-`' and then the 'e' keys on my Swiss-French keyboard generates a single KeyTyped event with the 'é' character.

Some examples of Java KeyEvents:

D[] stands for KeyPressed, with keyCode name and number
U[] stands for KeyReleased, with keyCode name and number
C[] stands for KeyTyped, with character and codePoint

a       D[A:65] C[a:97] U[A:65]
Shift   D[Shift:16] U[Shift:16]
Shift-a D[Shift:16] D[A:65] C[A:65] U[A:65] U[Shift:16]
Space   D[Space:32] C[ :32] U[Space:32]
Enter   D[Enter:10] C[:13] U[Enter:10]
Esc     D[Esc:27] C[:(none)] U[Esc:27]
Tab     D[Tab:9] C[:9] U[Tab:9]

In My Swiss-French keyboard, I have a key that directly generates the accented letter 'è':
è       D[Open Bracket:91] C[è:232] U[Open Bracket:91]

For generating 'é', I need to type to keys, first the 'Alt-`' and then the 'e':
Alt` e  D[Equals:61] C[:(none)] U[Equals:61] D[E:69] C[ê:234] U[E:69]

For generating '@', I need to type Alt and G:
alt-g   D[Alt:18] D[G:71] C[@:64] U[G:71] U[Alt:18]

For generating '#', I need to type Alt and 3:
Alt-3   D[Alt:18] D[3:51] C[#:35] U[3:51] U[Alt:18]

For generating '&', I need to type Shift and -6:
Shift-6  D[Shift:16] D[6:54] C[&:38] U[6:54] U[Shift:16]

The Up key does not fire a KeyTyped event, only the KeyPressed and KeyReleased event.
Up      D[Up:38] U[Up:38]

Here I select three letters (with Shift Rights) and copy them to the clipboard (with Crtl-C):
D[Shift:16] D[Right:39] U[Right:39] D[Right:39] U[Right:39] D[Right:39] U[Right:39] U[Shift:16]
D[Ctrl:17] D[C:67] C[�:3] U[C:67] U[Ctrl:17]

Note: sometimes, not always, key codes and code points have the same number. But they always have a different semantics. For instance:

     KeyPressed/KeyReleased    KeyTyped
     key code                  code point
A         65                   65
a         65                   97
Up        38                   -
&         -                    38

The '&' character cannot typically be produced by pressing a single key (you need to type Shift-6 in my Swiss-French keyboard to generate it), and so it does not have a key code. Pressing the Up key does not produce a character, and so it does not have a code point. Here you have a list of key codes.

Note: I do not understand why we get KeyTyped events with some key combinations that do not produce a character. For instance, typing Crlt-C generates also a KeyTyped event with code point 3.

This software, DesktopKeyboard2Android, captures the key events and forwards them to the Android WifiKeyboard app, through Wifi or USB.

Unfortunately, forwarding all key events to WifiKeyboard app generates duplicated or incorrect characters on the phone. For instance:

  • typing 'a' should generate only 'a', but WifiKeyboard will generate 'aa' (not even 'Aa', don't know why).
  • typing 'Alt-g' on my Swiss-French keyboard should generate only '@', but WifiKeyboard will generate 'G@'.

One possibility is to forward only the KeyPressed and KeyReleased events. But then we miss the keyboard layout configuration. That is, typing first the 'Alt-`' and then the 'e' in my Swiss-French keyboard, would generate two characters '`e' instead of 'é' on the phone. That could be solved if WifiKeyboard app would allow selecting the layout configuration and generate itself the KeyTyped events accordingly. It would be like a combination of WifiKeyboard + External Keyboard apps.

WikiKeyboard is open-source, but I could not work on it because of my poor working conditions (see below the Story of this application). So, my option was to get the key events received from the laptop, and transform and forward them to WifiKeyboard app accordingly. This involves mainly, but not only, filtering out some of the KeyPressed/KeyReleased and KeyTyped events. Because of a lack of documentation about it, the logic implemented here has been based on experimenting, trail and error, and so it might not work in all systems and keyboards.

Story of this application

I am trekking in Nepal Annapurna region for more than one month. I use my laptop to organize photos and type my journal. Suddenly, the retro-illumination of my screen stops working, which means that I can only see very small regions of my screen if I put a torch in front of it, very painful to work with. Typing my journal into my android phone is not feasible. The Google Keyboard app makes it a bit faster to type long texts, but it does not work in the Catalan language.

I find the WifiKeyboard app, which allows me to use my laptop's keyboard to type into my android. That's fine for writing my journal. However, it is difficult to set-up each time that I want to type something, as the WifiKeyboard client requires to open a webpage in the laptop and click some parameters. That's difficult in my case as the laptop's screen is not working properly. There are two other issues: (1) I cannot type some of the accents on my Swiss-French keyboard, and (2) I cannot reorganize parts of the text as Crtl-C & Crtl-V do not work with the international keyboard.

So I decided to develop this software to solve these issues while trekking in Nepal Annapurna, with elevations from 2000 to 5000m. I travel in a very relaxed way, trekking long and fast some days, and resting in a hut at the top of a mountain (Tilicho lake, Khopra, Moharedanda) for a few days. The working conditions are a bit painful, as my laptop screen is hardly working, the wifi and internet connection works slowly and intermittently, there are power cuts, I use IntelliJ in a very small screen (I mirror my laptop screen to my Samsung Galaxy S4 using Chrome Remote Desktop), and the whole set-up only works from time to time (anybody can send me detailed instructions on how to mirror my osx laptop to my android phone through usb?). It is also an opportunity to see how would it be to work at the mountains. It is great! No cars, not even bicycles, I can take a break, watch the great landscape, go for a walk, and maybe get a new picture of the problem I am trying to solve. Sometimes the set-up fails (power cut, no wifi/internet) and I am forced to take such a nice break. And no, this does not spoil my trekking vacations. I have just taken three days out of five weeks. It is a good small brake. :)

Also, this is how it works in "remote areas". If I had been in a big city, I would have just taken my laptop to an Apple Center to fix it, or buy a new one, or buy an external USB keyboard for the android (which means you need money). In a remote area, people improvise solutions with whatever they have right there. Very nice! Also, it shows the big discrimination on access to information: in a big city, we can instantly browse a wikipedia page or watch a coursera.org video course. That was not the case here, with slow and intermittent internet connection.

desktopkeyboard2android's People

Contributors

alban-auzeill avatar dportabella avatar jcarsique avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.