Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Quick Piece of Code Advice - Toggling keyboard commands

  1. #1

    Quick Piece of Code Advice - Toggling keyboard commands

    Hello there!

    I'm just finishing up a code for a piece of hardware I'm currently building and I've come across a situation I'd like to be able to implement, and I imagine it's a fairly simple piece of code away for working!

    Essentially, I've got a push button which when pressed outputs a "[" keypress using keyboard.Write.

    What I would like is for the button to toggle between outputting first a "[" then a "]".

    The idea is this button is to Pause a piece of software, and then to use the same button to resume.

    Is this at all possible? And what would the code I'm missing look like?


    -Rory Maguire

  2. #2
    Senior Member
    Join Date
    Nov 2013
    if you had included your code snippet for detecting the button press and sending the '[' character I could have modified it to show you using the specific stuff you are using but...
    volatile uint8_t toggler=1;
    setup() { // do your set up bits }
    loop() {
      if(button_detected) {
        if(toggler) send("]"); else send("[");
    Is one way it can be done.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts