← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #670913]: Get key name in python

 

Question #670913 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/670913

Alex posted a new comment:
I'm not aware of the existence of this functionality. The [Key
Constants](http://sikulix-2014.readthedocs.io/en/latest/keys.html) help
page lists all of the available special keys. It would be trivial to
make a function that did this:

def print_special_key_string(key):
    """
    Given a special key constant return a string.
    :param key:
    :return:
    """
    if 'Key.' in key:
        key = key.replace('Key.', '')  # Strip the 'Key.' text if it exists.

    key_dict = {
        u'\r': 'Enter',
        u'': 'Window',
        u'': 'Escape',
        u'': 'ALT'
    }

    if key in key_dict:
        return key_dict[key]
    else:
        raise ValueError('Unable to locate %s in the Special Key dictionary.' % key)


print(print_special_key_string(Key.WIN))

I couldn't paste the full list in but you get the idea. Make sure you
set the encoding at the top of your file:

# -*- coding: utf-8 -*-

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.