Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Author: Seytonic
- * https://twitter.com/seytonic
- * https://www.youtube.com/seytonic
- * GIT:
- * https://github.com/Seytonic/Duckduino-microSD
- */
- #define UseMultiLangMethod_WindowsOnly false //by setting this to true alt+numpad method will be enabled for chars like "\/*;.," etc. meaning it will work with most encodings without the need for reflashing (suitable and recommended only for Windows though)
- #include <SPI.h>
- #include <SD.h>
- #include <string.h>
- #include "Keyboard.h"
- #define ENCODING_BYTE_DESIRED 0
- #define ENCODING_BYTE_USED 1
- #define ENCODING_BYTE_MODIFIER 2
- //no.properties Exact lenght: 71 (100 is just because of some paranoid need to have safe additional space :P)
- byte Encoding[3][100] = {
- {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x4D, 0x51, 0x57, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x69, 0x6D, 0x71, 0x77, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0xA0, 0xA3, 0xA4, 0xA7, 0xAB, 0xB5, 0xBD, 0xC5, 0xC6, 0xD8, 0xDF, 0xE5, 0xE6, 0xF0, 0xF8, 0xFE},
- {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x5C, 0x38, 0x39, 0x5C, 0x2D, 0x2C, 0x2F, 0x2E, 0x37, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2E, 0x2C, 0xEC, 0x30, 0xEC, 0x2D, 0x32, 0x61, 0x6D, 0x71, 0x77, 0x79, 0x7A, 0x38, 0x3D, 0x39, 0x5D, 0x2F, 0x3D, 0x61, 0x69, 0x6D, 0x71, 0x77, 0x79, 0x7A, 0x37, 0x7E, 0x30, 0x5D, 0x20, 0x33, 0x34, 0x7E, 0x34, 0x6D, 0x7E, 0x5B, 0x22, 0x3B, 0x73, 0x5B, 0x22, 0x64, 0x3B, 0x74},
- {0x81, 0x81, 0x81, 0x86, 0x81, 0x81, 0x00, 0x81, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x81, 0x00, 0x81, 0x81, 0x81, 0x86, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x86, 0x00, 0x86, 0x81, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x00, 0x86, 0x86, 0x00, 0x86, 0x81, 0x81, 0x00, 0x86, 0x00, 0x81, 0x81, 0x81, 0x86, 0x00, 0x00, 0x86, 0x00, 0x86}
- };
- byte KEYPAD[10] = {
- 234,
- 225,
- 226,
- 227,
- 228,
- 229,
- 230,
- 231,
- 232,
- 233
- };
- File myFile;
- boolean first = true;
- void setup() {
- String dip = ""; // Name of the file that will be opened
- // Sets the given pins as switches for the dip switches
- pinMode(6, INPUT_PULLUP);
- pinMode(7, INPUT_PULLUP);
- pinMode(8, INPUT_PULLUP);
- pinMode(9, INPUT_PULLUP);
- // Switches are checked, dip string is contructed
- if (digitalRead(6) == LOW){dip += "1";} else {dip += "0";}
- if (digitalRead(7) == LOW){dip += "1";} else {dip += "0";}
- if (digitalRead(8) == LOW){dip += "1";} else {dip += "0";}
- if (digitalRead(9) == LOW){dip += "1";} else {dip += "0";}
- dip += ".txt";
- if (!SD.begin(4)) {
- return;
- }
- // Desired file is opened
- myFile = SD.open(dip);
- if (myFile) {
- Keyboard.begin();
- String line = "";
- while (myFile.available()) {
- char m = myFile.read();
- if (m == '\n'){
- Line(line);
- line = "";
- }
- else if((int) m != 13)
- {
- line += m;
- }
- }
- Line(line);
- myFile.close();
- } else {
- }
- Keyboard.end();
- }
- void Line(String l)
- {
- int space_1 = l.indexOf(" ");
- if (space_1 == -1)
- {
- Press(l);
- }
- else if (l.substring(0,space_1) == "STRING")
- {
- Print(l.substring(space_1 + 1));
- }
- else if (l.substring(0,space_1) == "DELAY")
- {
- int delaytime = l.substring(space_1 + 1).toInt();
- delay(delaytime);
- }
- else if(l.substring(0,space_1) == "REM"){}
- else
- {
- String remain = l;
- while(remain.length() > 0)
- {
- int latest_space = remain.indexOf(" ");
- if (latest_space == -1)
- {
- Press(remain);
- remain = "";
- }
- else
- {
- Press(remain.substring(0, latest_space));
- remain = remain.substring(latest_space + 1);
- }
- delay(5);
- }
- }
- Keyboard.releaseAll();
- }
- void Press(String b)
- {
- if(b.length() == 1)
- {
- char c = b[0];
- Keyboard.press(c);
- }
- else if (b.equals("ENTER"))
- {
- Keyboard.press(KEY_RETURN);
- }
- else if (b.equals("CTRL"))
- {
- Keyboard.press(KEY_LEFT_CTRL);
- }
- else if (b.equals("SHIFT"))
- {
- Keyboard.press(KEY_LEFT_SHIFT);
- }
- else if (b.equals("ALT"))
- {
- Keyboard.press(KEY_LEFT_ALT);
- }
- else if (b.equals("GUI"))
- {
- Keyboard.press(KEY_LEFT_GUI);
- }
- else if (b.equals("UP") || b.equals("UPARROW"))
- {
- Keyboard.press(KEY_UP_ARROW);
- }
- else if (b.equals("DOWN") || b.equals("DOWNARROW"))
- {
- Keyboard.press(KEY_DOWN_ARROW);
- }
- else if (b.equals("LEFT") || b.equals("LEFTARROW"))
- {
- Keyboard.press(KEY_LEFT_ARROW);
- }
- else if (b.equals("RIGHT") || b.equals("RIGHTARROW"))
- {
- Keyboard.press(KEY_RIGHT_ARROW);
- }
- else if (b.equals("DELETE"))
- {
- Keyboard.press(KEY_DELETE);
- }
- else if (b.equals("PAGEUP"))
- {
- Keyboard.press(KEY_PAGE_UP);
- }
- else if (b.equals("PAGEDOWN"))
- {
- Keyboard.press(KEY_PAGE_DOWN);
- }
- else if (b.equals("HOME"))
- {
- Keyboard.press(KEY_HOME);
- }
- else if (b.equals("ESC"))
- {
- Keyboard.press(KEY_ESC);
- }
- else if (b.equals("INSERT"))
- {
- Keyboard.press(KEY_INSERT);
- }
- else if (b.equals("TAB"))
- {
- Keyboard.press(KEY_TAB);
- }
- else if (b.equals("END"))
- {
- Keyboard.press(KEY_END);
- }
- else if (b.equals("CAPSLOCK"))
- {
- Keyboard.press(KEY_CAPS_LOCK);
- }
- else if (b.equals("F1"))
- {
- Keyboard.press(KEY_F1);
- }
- else if (b.equals("F2"))
- {
- Keyboard.press(KEY_F2);
- }
- else if (b.equals("F3"))
- {
- Keyboard.press(KEY_F3);
- }
- else if (b.equals("F4"))
- {
- Keyboard.press(KEY_F4);
- }
- else if (b.equals("F5"))
- {
- Keyboard.press(KEY_F5);
- }
- else if (b.equals("F6"))
- {
- Keyboard.press(KEY_F6);
- }
- else if (b.equals("F7"))
- {
- Keyboard.press(KEY_F7);
- }
- else if (b.equals("F8"))
- {
- Keyboard.press(KEY_F8);
- }
- else if (b.equals("F9"))
- {
- Keyboard.press(KEY_F9);
- }
- else if (b.equals("F10"))
- {
- Keyboard.press(KEY_F10);
- }
- else if (b.equals("F11"))
- {
- Keyboard.press(KEY_F11);
- }
- else if (b.equals("F12"))
- {
- Keyboard.press(KEY_F12);
- }
- }
- void loop() {
- // nothing happens after setup
- }
- void Print(String inStr)
- {
- int enc_index;
- for(byte i=0; i< inStr.length(); i++)
- {
- if (UseMultiLangMethod_WindowsOnly && ((!isalnum(inStr[i]) && inStr[i] != ' ') || IsException(inStr[i]))) //if character is punctuation or requires different button to be pressed in different keyboard language settings then use alt+numpad method
- //if(IsCharSpecial(inStr[i]))
- {
- //Serial.print("special char = ");
- //Serial.println(inStr[i]);
- byte hundreds = (byte)inStr[i] / 100;
- byte dozens = ((byte)inStr[i] - (hundreds*100)) / 10;
- byte singles = (byte)inStr[i] - (hundreds*100) - (dozens*10);
- //Serial.print(hundreds);
- //Serial.print(dozens);
- //Serial.println(singles);
- Keyboard.press(KEY_LEFT_ALT);
- PressRelease((char)KEYPAD[hundreds], 5);
- PressRelease((char)KEYPAD[dozens], 5);
- PressRelease((char)KEYPAD[singles], 5);
- Keyboard.releaseAll();
- continue;
- }
- enc_index = GetKeyIndex(inStr.charAt(i), Encoding[ENCODING_BYTE_DESIRED]);
- if(enc_index < 256)
- {
- if(Encoding[ENCODING_BYTE_MODIFIER][enc_index] > 0)
- {
- Keyboard.press(Encoding[ENCODING_BYTE_MODIFIER][enc_index]);
- delay(5);
- }
- Keyboard.press(Encoding[ENCODING_BYTE_USED][enc_index]);
- delay(5);
- }
- else
- {
- Keyboard.press(inStr.charAt(i));
- delay(5);
- }
- Keyboard.releaseAll();
- }
- }
- int GetKeyIndex(byte c, byte* char_array)
- {
- for(byte i=0;i<strlen(char_array);i++)
- {
- if(c == char_array[i])
- {
- return i;
- }
- }
- return 256;
- }
- void PressRelease(char c, byte timeDelay)
- {
- Keyboard.press(c);
- delay(timeDelay);
- Keyboard.release(c);
- }
- /*
- Exceptions are the letters that require different button being pressed in different lang settings
- (so if letter == exception then use alt+numpad method, otherwise use the normal typing because it's faster to press 1 instead of 4 buttons)
- these exceptions are listed to make the typing process faster because using alt+numpad method for all the characters appears to be too slow
- german - yz
- french - qamwz
- dutch - qamwz
- turkish - i
- azerbaijani - totally uncompatible
- */
- #define EXCEPTIONS_SIZE 7
- char exceptions[EXCEPTIONS_SIZE] = {
- 'y',
- 'z',
- 'q',
- 'a',
- 'm',
- 'w',
- 'i',
- };
- /*
- bool IsCharSpecial(char c)
- {
- byte b = (byte)c;
- if((b == 32 || (b >= 49 && b <= 57) || (b >= 65 && b <= 90) || (b >= 97 && b <= 122)) && IsntException(b))
- {
- return false;
- }
- return true;
- }
- */
- bool IsException(char c)
- {
- for(byte i=0; i<EXCEPTIONS_SIZE; i++)
- {
- if(c == exceptions[i])
- {
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement