summaryrefslogtreecommitdiff
path: root/src/macros/4-move_mouse.py
blob: 85979ea615fe93aff0b703cf7ed6246b4fe717c3 (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
import skeleton

class Color(object):
    """ Return a color which may change over time.
    """
    def __init__(self, code):
        self.code = code

    def __int__(self):
        return self.code

class NoIdle(object):

    def __init__(self):
        self.x = 10
        self.color = Color(0x000500)
        self.active = False

    def update(self, macropad):
        if not self.active:
            return

        self.x *= -1
        macropad.mouse.move(
                 self.x,
                 0,
                 0)
        # Update the color in red or blue in order to show that the heartbeat
        # is active.
        self.color.code = 0x010000 if self.x > 0 else 0x000001
        macropad.pixels[4] = int(self.color)
        macropad.pixels.show()

    def pause(self, macropad, key, pressed):
        if pressed:
            self.active = not self.active
        if self.active:
            self.update(macropad)
        else:
            # Restore the default color (green)
            self.color.code = 0x000500
            macropad.pixels[4] = int(self.color)
            macropad.pixels.show()


def build_application():
    configuration = skeleton.Configuration("NoIdle")
    actor = NoIdle()
    configuration.setTick(5000, actor.update)
    configuration.registerKey(4,  "switch",   actor.pause,    actor.color)
    configuration.is_layout = False
    return configuration

configuration = build_application()