Skip to content

Commit 851d45f

Browse files
committed
Update Turbo Coder to send Tab on long press instead of double press
1 parent d8d1cf0 commit 851d45f

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Turbo Coder](./hardware.jpg)
44

5-
Turbo Coder is a simple hardware device that enables you to quickly accept Copilot suggestions in VSCode. It acts as a USB keyboard and sends CTRL+Right Arrow on single button press and Tab on double press.
5+
Turbo Coder is a simple hardware device that enables you to quickly accept Copilot suggestions in VSCode. It acts as a USB keyboard and sends CTRL+Right Arrow on single button press and Tab on long press.
66

77
## Hardware
88

platformio.ini

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ board = leonardo
1414
framework = arduino
1515
lib_deps =
1616
arduino-libraries/Keyboard@^1.0.6
17-
arduinogetstarted/ezButton@^1.0.4
18-
pfeerick/elapsedMillis@^1.0.6
17+
bxparks/AceButton@^1.10.1

src/main.cpp

+25-27
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,43 @@
11
#include <Arduino.h>
22
#include <Keyboard.h>
3-
#include <ezButton.h>
4-
#include <elapsedMillis.h>
3+
#include <AceButton.h>
4+
using namespace ace_button;
55

6-
ezButton button(11);
7-
bool isPressed = false;
8-
elapsedMillis t;
6+
const int PIN_BUTTON = 11;
7+
8+
AceButton button(PIN_BUTTON);
9+
10+
void handleEvent(AceButton *, uint8_t, uint8_t);
911

1012
void setup()
1113
{
12-
button.setDebounceTime(50);
14+
ButtonConfig *buttonConfig = ButtonConfig::getSystemButtonConfig();
15+
buttonConfig->setEventHandler(handleEvent);
16+
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
17+
buttonConfig->setLongPressDelay(300);
18+
19+
pinMode(PIN_BUTTON, INPUT_PULLUP);
1320
}
1421

1522
void loop()
1623
{
17-
button.loop();
24+
button.check();
25+
}
1826

19-
if (button.isPressed())
27+
void handleEvent(AceButton *button, uint8_t eventType, uint8_t buttonState)
28+
{
29+
if (eventType == AceButton::kEventPressed)
2030
{
21-
if (!isPressed)
22-
{
23-
isPressed = true;
24-
t = 0;
25-
}
31+
Keyboard.press(KEY_LEFT_CTRL);
32+
Keyboard.press(KEY_RIGHT_ARROW);
33+
delay(10);
34+
Keyboard.releaseAll();
2635
}
27-
28-
if (isPressed && t >= 300)
36+
if (eventType == AceButton::kEventLongPressed)
2937
{
30-
if (button.getCount() == 1)
31-
{
32-
Keyboard.press(KEY_LEFT_CTRL);
33-
Keyboard.press(KEY_RIGHT_ARROW);
34-
}
35-
if (button.getCount() > 1)
36-
{
37-
Keyboard.press(KEY_TAB);
38-
}
39-
38+
Keyboard.press(KEY_TAB);
4039
delay(10);
4140
Keyboard.releaseAll();
42-
button.resetCount();
43-
isPressed = false;
4441
}
42+
Serial.print("Button event: ");
4543
}

0 commit comments

Comments
 (0)