F13 Thru F24 Keys Help

Generating F13 .. F18 function key pressed

I recently use the code liked above for my macro keyboard and it works perfectly fine, however I still have a few more free keys on it. I don't know too much about coding & I like to ask if some of you all can figure out how to increase the number of possibilities for these extra keys, a good example I think will be to create combinations with CTRL or ALT + F13...24.

Let me know if I did not explain myself right.
Thanks in ahead.

/* Code for f13-f24 keys working
  Really basic setup for individual pins per button.
  Circuit; push button connected between pins and ground.
  Not using delay. 30 ms debounce

  Based on the code by Fexduino from - http://forum.arduino.cc/index.php?topic=324554.0
*/

#include "Keyboard.h" // v1.0.2 or later of the keyboard library required

/* const int buttonPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
  Due pins above, remove comment out if using Due
  pro micro (leonardo to the IDE board list) below, comment out if using a Due
*/
const byte buttonPins[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 14, 15}; // - continuing in order 18, 19, 20, 21, should you want to add more.

const int buttonKeys[] = {KEY_LALT, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23, KEY_F24};
bool buttonStates[13] = { false};

const int pollRate = 30; // change this figure if the debounce number needs to be higher or lower
unsigned long m = 0;

void setup() {
  for (byte i = 0; i < sizeof(buttonPins); i++)
    pinMode(buttonPins[i], INPUT_PULLUP);

  m = millis();
}

void loop() {
  if (millis() - m > pollRate) {
    m += pollRate;

    for (byte i = 0; i < sizeof(buttonPins); i++) {
      bool state = digitalRead(buttonPins[i]);

      if (state == LOW && !buttonStates[i]) {
        buttonStates[i] = true;
        Keyboard.press(buttonKeys[i]);
      }
      else if (state == HIGH && buttonStates[i]) {
        buttonStates[i] = false;
        Keyboard.release(buttonKeys[i]);
      }
    }
  }
}
1 Like

Thanks for your response, but i think i did not explain well what I wanted.

All I am looking for is a way to create more options using keys combinations for ex. CTRL+F13, CTRL+F14...

The image below should help to understand more.
image

ah, yes, i have understood but then written just like a simple button

#include "Keyboard.h" 

const byte buttonPins[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 14, 15}; // - continuing in order 18, 19, 20, 21, should you want to add more.
const byte ALTbuttonPins[] = { 0, 1, 18, 19}; //etc., KEY_LALT + (KEY_F13, KEY_F14, KEY_F15, KEY_F16)

const int buttonKeys[] = { KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23, KEY_F24};
bool buttonStates[13] = { false};

const int pollRate = 30; // change this figure if the debounce number needs to be higher or lower
unsigned long m = 0;

void setup() {
  for (byte i = 0; i < sizeof(buttonPins); i++)
    pinMode(buttonPins[i], INPUT_PULLUP);

  m = millis();
}

void loop() {
  if (millis() - m > pollRate) {
    m += pollRate;//KEY_LALT,

    for (byte i = 0; i < sizeof(ALTbuttonPins); i++) {
      bool state = digitalRead(ALTbuttonPins[i]);

      if (state == LOW && !buttonStates[i]) {
        buttonStates[i] = true;
        Keyboard.press(KEY_LALT);
        Keyboard.press(buttonKeys[i]);
      }
      else if (state == HIGH && buttonStates[i]) {
        buttonStates[i] = false;
        Keyboard.releaseAll();
      }
    }
  }
  for (byte i = 0; i < sizeof(buttonPins); i++) {
      bool state = digitalRead(buttonPins[i]);

      if (state == LOW && !buttonStates[i]) {
        buttonStates[i] = true;
        Keyboard.press(buttonKeys[i]);
      }
      else if (state == HIGH && buttonStates[i]) {
        buttonStates[i] = false;
        Keyboard.release(buttonKeys[i]);
      }
    }
  }
}
1 Like

I used the key SHIFT instead and did some adjustments to it.
It is working perfectly thank you so much.

#include "Keyboard.h" 

const byte buttonPins[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12}; // - continuing in order 18, 19, 20, 21, should you want to add more.
const byte ALTbuttonPins[] = { 13, 14, 15, 16, 17, 18, 19}; //etc., KEY_LEFT_SHIFT + (KEY_F13, KEY_F14, KEY_F15, KEY_F16...)

const int buttonKeys[] = { KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23, KEY_F24};
bool buttonStates[19] = { false}; // TOTAL OF KEYS USED

const int pollRate = 30; // change this figure if the debounce number needs to be higher or lower
unsigned long m = 30;

void setup() {
  for (byte i = 0; i < sizeof(buttonPins); i++)
  pinMode(buttonPins[i], INPUT_PULLUP);

  m = millis();
}

void loop() {
  if (millis() - m > pollRate) {
    m += pollRate;//KEY_LEFT_SHIFT

    for (byte i = 0; i < sizeof(ALTbuttonPins); i++) {
      bool state = digitalRead(ALTbuttonPins[i]);

      if (state == LOW && !buttonStates[i]) {
        buttonStates[i] = true;
        Keyboard.press(KEY_LEFT_SHIFT);
        Keyboard.press(buttonKeys[i]);
      }
      else if (state == HIGH && buttonStates[i]) {
        buttonStates[i] = false;
        Keyboard.releaseAll();
      }
    }
  }
  for (byte i = 0; i < sizeof(buttonPins); i++) {
      bool state = digitalRead(buttonPins[i]);

      if (state == LOW && !buttonStates[i]) {
        buttonStates[i] = true;
        Keyboard.press(buttonKeys[i]);
      }
      else if (state == HIGH && buttonStates[i]) {
        buttonStates[i] = false;
        Keyboard.releaseAll();//FOR SOME REASON THE KEY SHIFT STAYED PRESS AFTER 
      }
    }
  }
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.