Entries in the Category “Python”

Pausing Vynk for now

written by cryzed, on May 21, 2010 9:35:00 PM.

Now that was quick – didn’t even last longer than my usual projects. The reason I’m pausing Vynk for now is because the java.awt.Robot class apparently isn’t able to send anything besides a subset of the ASCII charset characters to non-Swing windows.

Well… it is possible, but no one in their right mind would even think about using these workarounds. For Windows operating systems that would for example be holding down the CTRL-key and entering some fancy combinations on the numpad just to get an umlaut of some kind let alone accented characters.

Maybe I’m expecting too much – but I also couldn’t find any way to convert a character to a keycode so I could easily send it with java.awt.Robot. That’s why I ended up creating another ugly workaround to get the basic alphanumeric characters into a nice dictionary and additionally had to create a seperate dictionary for special characters so I could later access them easily.

KEY_EVENTS = dict((key[3:], value._doget(None)) for key, value in
                  KeyEvent.__dict__.items() if key.startswith('VK_'))

SPECIAL_CHARACTER_KEY_EVENTS = {
    ' ': KeyEvent.VK_SPACE,
    '!': KeyEvent.VK_EXCLAMATION_MARK,
    '"': KeyEvent.VK_QUOTEDBL,
    '#': KeyEvent.VK_NUMBER_SIGN,
    '$': KeyEvent.VK_DOLLAR,
    '&': KeyEvent.VK_AMPERSAND,
    ...
}

KEY_EVENTS.update(SPECIAL_CHARACTER_KEY_EVENTS)

But even with all that I’m still not able to send simple umlauts, such as ‘ü’, ‘ä’ or ‘ö’ to non-Swing windows or even a simple ‘?’ for that matter. Maybe I’m doing something completely wrong and it’s all my fault or just maybe java.awt.Robot isn’t as well-kept as the other Java libraries… or I simply don’t get Java. It’s probably a bit of everything.1

If I ever start working on it again I’ll probably use python-xlib. Of course it wouldn’t be cross-platform then anymore, but really, it’s not like Windows is in any need of desktop automation software with stuff like AutoIt and AutoHotKey around.

1) If anyone knows how to do these things contact me please or simply leave a comment.

Vynk – A Jython desktop automation library

written by cryzed, on May 18, 2010 8:05:00 PM.

I finally started something worthwile: Vynk, a desktop automation library for Jython. Why Jython you ask? Well for one, it’s Python – just implemented on top of the JVM. Additionally the Java standard libraries already come with java.awt.Robot which makes all the coding a hell of a lot easier since most of it is already done. That’s why Vynk is actually only a really thin wrapper around java.awt.Robot trying to make it all a bit more “pythonic” and organized.

Currently the Vynk-package only consists of four files: __init__.py, keyboard.py, mouse.py and screen.py. __init__.py is currently empty and the other files contain the functionality you would probably expect based on their names. Currently only the module for handling the mouse is “pythonic” – if you want to call it that. The module handling the screen implements the methods exposed by the java.awt.Robot class for now but returns complex java class instances – I’ll probably dumb that down quite a bit. Same goes for the module that handles the keyboard, but the main functionality, pressing and releasing keys, isn’t even implemented yet – so that will have to wait for now.

If you are interested in contributing something to the project you can visit my Bitbucket account and send me some patches if you feel like it – or make a pull request. Also if something is extremely wrong with my code don’t hesitate to tell me please – as mentioned here I don’t consider myself very proficient in Python and neither should you.

The ultimate goal is to have a Jython library which feels “pythonic” and ultimatively exposes the same functionality as the java.awt.Robot class. Similiar projects include, although Windows-only, AutoIt and AutoHotKey.