Forum quick-typer uses Leonardo and keypad for common phrases

I find myself often typing in the same links when answering forum questions, and wanted to automate the process a bit.

Example: http://www.gammon.com.au/interrupts

Previously I had a list of them in one place (on a Stickies document on the Mac) but still had to switch apps, highlight, copy, switch back, paste.

Then with the Leonardo and its ability to emulate a keyboard I saw an opportunity. Here:

A 16-key keypad is hooked up to the Leonardo, and when a key is pressed it sends a pre-configured text item to the keyboard. Assuming the cursor is on a forum message, the link is now promptly inserted.

Code is simple:

 #include <Keypad2.h>

  const byte ROWS = 4;
  const byte COLS = 4; 
  char keys[ROWS][COLS] = {
    {'1', '2', '3', 'A'},
    {'4', '5', '6', 'B'},
    {'7', '8', '9', 'C'},
    {'*', '0', '#', 'D'},
  };
  
  byte rowPins[ROWS] = {6, 7, 8, 9}; //connect to the row pinouts of the keypad
  byte colPins[COLS] = {2, 3, 4, 5}; //connect to the column pinouts of the keypad
  
  // Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup ()
{
  // initialize control over the keyboard:
  Keyboard.begin();
}  // end of setup

void loop () 
  {
   byte key =  kpd.getKey();
   if (!key)
     return;
     
  switch (key)
    {
    case '1': Keyboard.println (F("http://www.gammon.com.au/interrupts")); break;
    case '2': Keyboard.println (F("http://www.gammon.com.au/i2c")); break;
    case '3': Keyboard.println (F("http://www.gammon.com.au/spi")); break;
 
    // and so on ...
      
    } // end of switch
  } // end of loop

Excellent idea Nick - I could do with one for texting on my mobile phone!

That's great Nick,

However I think this is like shooting rabbits with a rocket. I think Arduino is OK for prototyping, but in the spirit of hacking something like DIY USB password generator | Code and Life or USB Business Card | Eleccelerator is more educational and not so hard to do as well for a fraction of the price.

Please don't get me wrong, I don't mean to lessen the achievement you have, just my recommendation.

Thanks for the links. Actually the Leonardo doubles up as my Leonardo test bed, and I just re-upload the phrase-generator when not being used for something else.

I also have another processor in another room using the "cheap USB" interface, dedicated to supplying a password to a web site that keeps asking for it every 10 minutes, grrrrr, so I thought *&^%$#@ them, I'll hit a button when needed.

Brilliant work as usual , Nick !!

I love it.


Rob

Wow. That's brilliant Nick.

I get what martin_bg means (ie to the man with a hammer, every problem is a nail) but I can't help but love this idea.

Forum mods the world over can now avoid RSI because of your work :slight_smile:
Geoff

Nice, but I would have solved something like this autoit AutoIt Scripting Language - AutoIt or autohotkey.

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting.

Yes, but I have OS/X.

I ended up running out of buttons for all the things I wanted to say such as "please don't cross post".

This variation adopts the idea of a "shift key". The "" key on the keypad now puts the keypad into "shifted" mode. An LED (and resistor) connected to D13 glows to indicate you have the alternate set of messages. Pressing "" again cancels shift. Also it drops out of shift as soon as you use the shifted message (you could delete that line).

This now lets you have 30 messages rather than 16.

// Author: Nick Gammon
// Date: 5th July 2012
// Modified: 22 October 2012

 #include <Keypad2.h>

const byte ROWS = 4;
const byte COLS = 4; 

char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'},
};

byte rowPins[ROWS] = {6, 7, 8, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4, 5}; //connect to the column pinouts of the keypad
  
const byte ledPin = 13;
boolean alternateMessages = false;

  // Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup ()
{
  // initialize control over the keyboard:
  Keyboard.begin();
  pinMode (ledPin, OUTPUT);
}  // end of setup

void loop () 
  {
   
   // show which messages are active
   digitalWrite (ledPin, alternateMessages ? HIGH : LOW);
   
   byte key =  kpd.getKey();
   if (!key)
     return;
     
  if (alternateMessages)
    {
    switch (key)
      {
      case '1': Keyboard.println (F("Alternate message A")); break;
      case '2': Keyboard.println (F("Alternate message B")); break;
      case '3': Keyboard.println (F("Alternate message C")); break;

// ... and so on ...
 
      
      case '*': alternateMessages = false; break;
      
      } // end of switch
        
    // go back to main messages
    alternateMessages = false; 
    
    } // end of if alternate messages
    
  else
  
    // normal messages
    {
    switch (key)
      {
      case '1': Keyboard.println (F("http://www.gammon.com.au/interrupts")); break;
      case '2': Keyboard.println (F("http://www.gammon.com.au/i2c")); break;
      case '3': Keyboard.println (F("http://www.gammon.com.au/spi")); break;

// ... and so on ...
      
      case '*': alternateMessages = true; break;
        
      } // end of switch
      
    }  // end of normal messages
    
  } // end of loop

Tips:

You can do other things like adding a newline into your message:

        Keyboard.println ();

And if you want to arrow back inside a message (eg. do code tags and put the cursor back inside the tags):

        for (int i = 0; i < 8; i++) 
          {
          Keyboard.press (KEY_LEFT_ARROW);
          Keyboard.releaseAll();
          }

Very nice idea Nick, specialy for moderators. :wink: :wink: :wink:

Ciao Uwe

Great work nick
As you started starring you can start multiple ties (reflected by multiple leds) to have as many texts as you want.

Best regards
Jantje

Yes, good idea. It will be like a huge custom "boilerplate" generator.