summaryrefslogtreecommitdiff
path: root/12key-arduino/ModeMouse.h
diff options
context:
space:
mode:
Diffstat (limited to '12key-arduino/ModeMouse.h')
-rw-r--r--12key-arduino/ModeMouse.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/12key-arduino/ModeMouse.h b/12key-arduino/ModeMouse.h
new file mode 100644
index 0000000..c68a70c
--- /dev/null
+++ b/12key-arduino/ModeMouse.h
@@ -0,0 +1,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;
+};