summaryrefslogtreecommitdiff
path: root/README
blob: 561d8697f6a2d696091cff54fbe9c11419fb1ae5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Keyboard-python is a simple module for parsing keyboard input.  It is useful
because it can tell you keypresses without the need for the Enter key to be
pressed and can parse the following:

F-keys
Home
End
PageUp
PageDown
Tab
Insert
Delete
Escape
Alt modified keys
Ctrl modified keys

Objects:

    Key(name)
        Takes a string name.

    KeyCombination(*keys):
        Takes either instances of Key or strings which are given to new Key
        instances as a name. If given only one Key it is considered
        equivelent to that Key, e.g. KeyCombination('j') == Key('j') is true

        contains_key(key):
            return boolean determined by whether key is in the combination of
            self

        add_key(key):
            add copy of key to the combination of self

        add_keyCombination(instance_of_KeyCombination):
            for each key in the instance given as an argument, add that key to
            self

        remove_key(key):
            if the combination includes a key which shares a name with the key
            given to the function then remove it from the combination

        diff(instance_of_KeyCombination):
            return a list of copies of keys that appear in exactly one of self
            and the argument given

Functions:

    getkey(fd)
        waits for keypress and returns returns KeyCombination containing all
        keys pressed.

    queue_keypresses(q,signal,fd)
        takes a Queue q, a mutable with boolean value signal. While signal is
        true it listens for keypresses putting them in q.

Example:

    import sys
    import keyboardpython as kbpy

    alt_A = kbpy.Key('A',key.ALT)
    alt_a = kbpy.Key('a',key.ALT)

    fd = sys.stdin.fileno()
    kbpy.init(fd)
    k = getkey(fd)
    kbpy.close(fd)

    if k == alt_A:
        print "You pressed Alt+A!"
    elif k == alt_a:
        print "You pressed Alt+a!"
    elif k.contains_key(key.ALT):
        print "You pressed Alt but not A"
    elif k.string in 'aA':
        print "You pressed a but not Alt"
    else:
        print "You didn't press Alt or A :("