I have an Arduino Pro Micro that is connected to a motion sensor. I want the motion sensor to trigger a Keyboard key but it has to be a key that will not generate a real keyboard function. I got my code working with the Right and Left CTRL keys but I need more keys. Which is why I would like to use f-13 to F-24.
I found this Keyboard/src at master · arduino-libraries/Keyboard · GitHub which I was thinking might help but no luck. I am new to Arduino so the more details you can provide the better.
What I expect this code to do is when the motion sensor is triggered it will send a virtual keyboard press to the computer. I have another program on my computer listening for the virtual Keyboard press. When the keyboard press is received my program will do something.
As of now I can receive a Left CTRL and the Right CTRL press and my program can work.
What I also find odd is the code for the Arduino key code is different than the one I use in my software. For example, Arduino defines the Left CTRL as 128 but my application defines the Left CTRL as 163. But using the 128 my software can read this and it works. I found a post that says f-13 is 240 but this did not work.
#include <Keyboard.h>
int sensorPin = 10;
void setup()
{
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
void sendWakeUp(void);
void loop()
{
delay(2000);
if (digitalRead(sensorPin) == 1)
{
sendWakeUp();
}
if (digitalRead(sensorPin) == 0)
{
sendSleep();
}
}
void sendSleep(void)
{
Serial.println(digitalRead(sensorPin)); // see pin reading
//Keyboard.write(177); //KEY_Escape
Serial.println("sleep");
}
void sendWakeUp(void)
{
Serial.println(digitalRead(sensorPin)); // see pin reading
Keyboard.write(240); //Key send F-13 - does not work
//Keyboard.write(128); //KEY_LEFT_CTRL - For stage 2 motion sensor - works
//Keyboard.write(132); //KEY_RIGHT_CTRL - For stage 1 motion sensor - works
Serial.println("wake up");
}
I have looked and I have not found a clear answer to this issue.
Thank you for your help