summaryrefslogtreecommitdiff
path: root/12key-arduino/ModeMouse.h
blob: c68a70cc8b841ac0fb4f1a0a56bdf0681729c276 (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
80
81
#pragma once

#include <Mouse.h>
#include "Mode.h"


#define STEP_SIZE 3

#define MOVE_KEYS (KEY_2 | KEY_4 | KEY_6 | KEY_8 | KEY_3 | KEY_9)
#define CLICK_KEYS (KEY_1 | KEY_7)


class ModeMouse : public Mode {
	public:
	MouseMode() {
		m_setStep = false;
		m_step = 2;
	}


	void reset() {}


	Mode * update(unsigned int keys) {
		if (keys & KEY_STAR) return Mode::modes[0];

		if (keys & KEY_HASH) {
			if (!m_setStep) {
				m_setStep = true;
				m_step = 1;
			}
			else {
				m_step *= 2;
			}
			return NULL;
		}

		m_setStep = false;

		if (keys & MOVE_KEYS)
			move(keys);
		else if (keys & CLICK_KEYS)
			click(keys);

		return NULL;
	}


	void move(unsigned int keys) {
		/* movement */
		if (keys & KEY_2) {
			for (int i=0; i<m_step; i++) Mouse.move(0, -STEP_SIZE, 0);
		}
		if (keys & KEY_4) {
			for (int i=0; i<m_step; i++) Mouse.move(-STEP_SIZE, 0, 0);
		}
		if (keys & KEY_6) {
			for (int i=0; i<m_step; i++) Mouse.move(STEP_SIZE, 0, 0);
		}
		if (keys & KEY_8) {
			for (int i=0; i<m_step; i++) Mouse.move(0, STEP_SIZE, 0);
		}

		/* scrolling */
		if (keys & KEY_3)
			Mouse.move(0, 0, 1);
		if (keys & KEY_9)
			Mouse.move(0, 0, -1);
	}

	void click(unsigned int keys) {
		if (keys & KEY_1)
			Mouse.click(MOUSE_LEFT);
		if (keys & KEY_7)
			Mouse.click(MOUSE_RIGHT);
	}

	protected:
	bool m_setStep;
	unsigned int m_step;
};