Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Programmed External Keys. #33

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e652b31
Create Programmed External Keys.ino
TheShubham99 Mar 17, 2020
d345997
Apply suggestions from code review
TheShubham99 Mar 18, 2020
f9f53f8
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 Mar 18, 2020
6132af0
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 Mar 18, 2020
623a9f1
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 Mar 18, 2020
d6e11f3
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 Mar 18, 2020
81773c3
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 Mar 18, 2020
e406919
Apply suggestions from code review
TheShubham99 Mar 18, 2020
d162f6c
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 Mar 18, 2020
a675091
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 Mar 18, 2020
0705b23
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 Mar 18, 2020
0bbeb9b
Code Readability & Optimization
TheShubham99 Mar 18, 2020
ae4b8ac
Updating ProgrammableButtons
TheShubham99 Mar 18, 2020
a0f90f4
Delete Programmed External Keys.ino
TheShubham99 Mar 18, 2020
5b8575f
Update examples/ProgrammableButtons/ProgrammableButtons.ino
TheShubham99 Mar 19, 2020
4147bd7
Update ProgrammableButtons.ino
TheShubham99 Mar 19, 2020
b2183ab
Update ProgrammableButtons.ino
TheShubham99 Mar 19, 2020
bfb8ff1
Update ProgrammableButtons.ino
TheShubham99 Mar 19, 2020
5282143
Update ProgrammableButtons.ino
TheShubham99 Mar 20, 2020
f91d0a4
Update examples/ProgrammableButtons/ProgrammableButtons.ino
TheShubham99 Mar 20, 2020
e3aaa42
Update examples/ProgrammableButtons/ProgrammableButtons.ino
TheShubham99 Mar 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions examples/ProgrammableButtons/ProgrammableButtons.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Programmed External Keys (Keyboard)

For native USB Arduino boards (e.g., Leonardo, Micro, MKR, Nano 33 IoT, Zero, Due)

When the first button is pressed, the Ctrl + C keyboard shortcut (copy) is emulated.
When the second button is pressed, the Ctrl + V keyboard shortcut (paste) is emulated.

The circuit:
The push buttons have 2 connectors.
Connect one to GND and the other to the I/O pin defined in the btnPin array.

created 18 March 2020
by Prathamesh Sahasrabhojane (TheShubham99)
*/

#include <Keyboard.h>

const int btnPin[] = {2, 3, 4, 5};
int pincount = 2;
int btnState[pincount];
int prevBtnState[] = {HIGH, HIGH, HIGH, HIGH};

unsigned long lastDebounceTime[] = {0, 0, 0, 0};
unsigned long debounceDelay = 50;
TheShubham99 marked this conversation as resolved.
Show resolved Hide resolved

void setup() {
for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) {
pinMode(btnPin[thisPin], INPUT_PULLUP);
}
Keyboard.begin();
}

// Place the actions needed after pin press here
void outputAction(int currentButton) {
TheShubham99 marked this conversation as resolved.
Show resolved Hide resolved
if (currentButton == 1) {
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press('c');
delay(100);
Keyboard.releaseAll();
}
else if (currentButton == 2) {
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press('v');
delay(100);
Keyboard.releaseAll();
}
}

void loop() {
for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) {
btnState[thisPin] = digitalRead(btnPin[thisPin]);

if ((btnState[thisPin] != prevBtnState[thisPin]) && (btnState[thisPin] == LOW)) {
if ((millis() - lastDebounceTime[thisPin]) > debounceDelay) {
outputAction(thisPin);
lastDebounceTime[thisPin] = millis();
}
}

prevBtnState[thisPin] = btnState[thisPin];
}
}