cliclick 3.0 released
Today I released version 3.0 of cliclick, a shell program for emulating mouse and keyboard events. The most important change – which had been the most requested feature – is the ability to type (almost) arbitrary text.
Versions prior to 3.0 could emulate only a few keys which where hardcoded in a list in the source. That was OK (and still is, as this code still exists and there is no need to remove it), as these were hardware-independend keys. “Hardware-independend” means that the Mac will recognize the key as the same, regardless of whether you use an American, a German or a Brazilian keyboard layout. On the other hand, the keys for almost all printable characters are hardware-dependend, so it is obvious that this feature was only of limited use, as it did not allow real “typing”.
For cliclick 3.0, I invested the time to write code for a runtime-generated mapping between keys and characters. This mapping is created by simply iterating over all keys that are hardware-dependend and collecting information on which character would be created without modifier keys, with Shift, with Alt or with Shift plus Alt. The nice thing is that this approach is generic and works for every keyboard layout.
Unfortunately, even this method is not perfect, as there are characters that can be entered by typing a sequence of characters, typically including so-called “dead” keys. An example is entering the German umlaut ü on a keyboard with American layout: there is no key for ü, but you can enter it by typing Alt-u (which will result in ¨ followed by u). I could not think of an algorithm to automatically identify these cases, so again, I had to resort to hard-coded mappings.
Naturally, this only works for the layouts and the characters which you will find listed in the code, so the support for these characters is fragmentary. But still, the ability to type in 3.0 is a huge improvement, as for most uses, the auto-generated mapping will be sufficient.
Having said all this, here is the basic approach how it works:
cliclick t:'Isn’t that nice?'
As a slightly more useful example (which will not work if your are running 10.10/Yosemite, as the way Spotlight works has changed), to start a Spotlight search for “Safari” on your Mac, you could use code like this:
cliclick kd:cmd kp:space ku:cmd w:500 t:'Safari' w:500 kp:arrow-up w:500 kp:return
This assumes your Spotlight keyboard shortcut is the default (⌘ Space). The “w:500” commands for waiting 500 milliseconds make a little clearer what exactly is happening.
That’s it so far. If you like cliclick, spread the word and/or contribute to it and/or invoke
cliclick -d ;-)