Hi Arduino Forum!
I am here with a very specific question.
I am currently working on a project where I, making use of a physical button, want to press an alt+f4 signal to my desktop. To do so, I was originally planning to use an Arduino Pro Micro and the keyboard.h module. But well, apparently, those don't go together...
A friend recommended me to make use of QMK but I have no idea on how to get started. Does anyone have some good sources to check out, or even better, a piece of code that sets an example on how to do this?
As always, if you need any information, please let me know!
In the meantime, thank you very much!
I'm making use of the code example provided by Arduino.
#include <Keyboard.h>
//declaring button pins
const int buttonPin = 2;
int previousButtonState = HIGH;
void setup() {
//declare the buttons as input_pullup
pinMode(buttonPin, INPUT_PULLUP);
Keyboard.begin();
}
void loop() {
//checking the state of the button
int buttonState = digitalRead(buttonPin);
//replaces button press with UP arrow
if (buttonState == LOW && previousButtonState == HIGH) {
// and it's currently pressed:
Keyboard.press(97);
delay(50);
}
if (buttonState == HIGH && previousButtonState == LOW) {
// and it's currently released:
Keyboard.release(97);
delay(50);
}
previousButtonState = buttonState;
}
This is the error I get:
C:\Users\Thijs\AppData\Local\Temp\.arduinoIDE-unsaved2022113-31488-1j1xlkz.adpg\sketch_dec3a\sketch_dec3a.ino: In function 'void setup()':
C:\Users\Thijs\AppData\Local\Temp\.arduinoIDE-unsaved2022113-31488-1j1xlkz.adpg\sketch_dec3a\sketch_dec3a.ino:11:3: error: 'Keyboard' was not declared in this scope
Keyboard.begin();
^~~~~~~~
C:\Users\Thijs\AppData\Local\Temp\.arduinoIDE-unsaved2022113-31488-1j1xlkz.adpg\sketch_dec3a\sketch_dec3a.ino: In function 'void loop()':
C:\Users\Thijs\AppData\Local\Temp\.arduinoIDE-unsaved2022113-31488-1j1xlkz.adpg\sketch_dec3a\sketch_dec3a.ino:21:5: error: 'Keyboard' was not declared in this scope
Keyboard.press(97);
^~~~~~~~
C:\Users\Thijs\AppData\Local\Temp\.arduinoIDE-unsaved2022113-31488-1j1xlkz.adpg\sketch_dec3a\sketch_dec3a.ino:27:5: error: 'Keyboard' was not declared in this scope
Keyboard.release(97);
^~~~~~~~
exit status 1
Compilation error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Right now, I got it on 'Arduino Pro or Pro Mini'.
There doesn't seem to be an option for Pro Micro.
Also seems to be the only option where it throws an error instead of saying the board is not responding.
Selecting a board in the IDE allows the IDE to use the correct library files for that board. If a suitable library file does not exist for the selected board then this will result in a "file not found" error
When choosing Arduino Micro, upload takes very long. After quite some time, I receive this:
Sketch uses 5856 bytes (20%) of program storage space. Maximum is 28672 bytes.
Global variables use 228 bytes (8%) of dynamic memory, leaving 2332 bytes for local variables. Maximum is 2560 bytes.
Connecting to programmer: .
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
Found programmer: Id = ""; type = �
Software Version = i. Hardware Version = .O
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: leave prog mode
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: exit bootloader
Failed uploading: uploading error: exit status 1