-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deleteknop.ino
54 lines (43 loc) · 1.97 KB
/
Deleteknop.ino
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
/*
Delete button source code by Herman Kopinga, [email protected].
created april 2013.
Easy as pie!
Modify to suit your own need.
Based directly on Keyboard Button test an Aruino code example
in the public domain originally by Tom Igoe.
http://www.arduino.cc/en/Tutorial/KeyboardButton
Added button debounce code of my own design, easy enough to understand?
Reason for debounce is explained on (of course) Wikipedia:
http://en.wikipedia.org/wiki/Switch#Contact_bounce
*/
const int buttonPin = A0; // input pin for pushbutton
boolean previousButtonState = HIGH; // for checking the state of a pushButton
unsigned long lastChange = 0; // moment of last change to button state.
boolean actionRequired = false; // by default, no action, only when the switch state changed.
// not really needed, added for clarity.
void setup() {
// make the pushButton pin an input:
pinMode(buttonPin, INPUT_PULLUP);
// initialize control over the keyboard:
Keyboard.begin();
}
void loop() {
// read the pushbutton:
int buttonState = digitalRead(buttonPin);
// if the button state has changed, save the moment this happened.
if (buttonState != previousButtonState) {
lastChange = millis();
actionRequired = true;
}
// if the button currently pressed and there hasn't been a change in 10 milliseconds.
if (buttonState == LOW && actionRequired && (millis() - lastChange) > 10) {
// Keyboard.press(KEY_LEFT_GUI); // optional: Windows or Command key
// Keyboard.press(KEY_LEFT_SHIFT); // optional: Any shift key
Keyboard.press(KEY_DELETE); // press the key
delay(10); // small delay, not always needed
Keyboard.releaseAll(); // release the key(s)
actionRequired = false; // action has run, make sure it won't run before next release.
}
// save the current button state for comparison next time:
previousButtonState = buttonState;
}