Advertisement
michalmonday

Malduino Lite Danish edit

Dec 1st, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* 2 LINES BELOW HAVE TO BE PASTED INTO MALDUINO LITE CODE RECEIVED FROM CONVERTER */
  2. void Print(String s);
  3. bool use_alt_numpad_method = false;
  4.  
  5.  
  6.  
  7.  
  8. /*
  9. Copyright (c) 2017 Seytonic, Spacehuhn (Licensed under MIT)
  10. For more information see: github.com/seytonic/malduino
  11. */
  12.  
  13. #include "Keyboard.h"
  14. #include "Mouse.h"
  15.  
  16. #define blinkInterval 50
  17. #define ledPin 3
  18. #define buttonPin 6
  19.  
  20. int defaultDelay = 4;
  21. int defaultCharDelay = 5;
  22. int rMin = 0;
  23. int rMax = 100;
  24.  
  25. bool ledOn = true;
  26.  
  27. void typeKey(int key){
  28.   Keyboard.press(key);
  29.   delay(defaultCharDelay);
  30.   Keyboard.release(key);
  31. }
  32.  
  33.  
  34.  
  35. void setup(){
  36.  
  37.   pinMode(buttonPin, INPUT_PULLUP);
  38.   pinMode(ledPin, OUTPUT);
  39.   digitalWrite(ledPin, HIGH);
  40.  
  41.     Keyboard.begin();
  42.     Mouse.begin();
  43.  
  44.     /* ----- Begin-Script -----*/
  45.    
  46.     /* [Parsed By Duckuino (Licensed under MIT) - for more information visit: https://github.com/Nurrl/Dckuino.js] */    
  47.     delay(1000);
  48.  
  49.     delay(defaultDelay);
  50.     Print("hello \\\\\\ world");  // replace all Keyboard.print("") with Print("")
  51.    
  52.     /* ----- End-Script -----*/
  53.    
  54.     Keyboard.end();
  55.  
  56. }
  57.  
  58. void loop(){
  59.   ledOn = !ledOn;
  60.   digitalWrite(ledPin, ledOn);
  61.   delay(blinkInterval);
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. /* COPY/PASTE ALL OF THE CODE BELOW AT THE END OF THE MALDUINO LITE CODE RECEIVED FROM CONVERTER */
  70.  
  71. byte KEYPAD[10] = {234, 225, 226, 227, 228, 229, 230, 231, 232, 233};
  72. #define ENCODING_BYTE_DESIRED 0
  73. #define ENCODING_BYTE_USED 1
  74. #define ENCODING_BYTE_MODIFIER 2
  75.  
  76. //dk.properties exact length: 69 (encoding generated using: https://github.com/hak5darren/USB-Rubber-Ducky/tree/master/Encoder/resources)
  77. byte Encoding[3][70] = {
  78.   {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, 0x5F, 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},
  79.   {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, 0xEC, 0x39, 0x2F, 0x61, 0x69, 0x6D, 0x71, 0x77, 0x79, 0x7A, 0x37, 0x3D, 0x30, 0x5D, 0x20, 0x33, 0x34, 0x7E, 0x34, 0x6D, 0x7E, 0x5B, 0x3B, 0x22, 0x73, 0x5B, 0x3B, 0x64, 0x22, 0x74},
  80.   {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, 0x86, 0x86, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x86, 0x86, 0x86, 0x00, 0x86, 0x81, 0x81, 0x00, 0x86, 0x00, 0x81, 0x81, 0x81, 0x86, 0x00, 0x00, 0x86, 0x00, 0x86}
  81. };
  82.  
  83. int GetKeyIndex(byte c, byte* char_array)
  84. {
  85.   for(byte i=0;i<strlen(char_array);i++)
  86.   {
  87.     if(c == char_array[i])
  88.     {
  89.       return i;
  90.     }
  91.   }
  92.   return 256;
  93. }
  94.  
  95.  
  96.  
  97. void Print(String inStr)
  98. {
  99.   int enc_index;
  100.   for(byte i=0; i< inStr.length(); i++)
  101.   {
  102.     if(use_alt_numpad_method && ((!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
  103.     {  
  104.       /* ALT + NUMPAD METHOD */
  105.       byte hundreds = (byte)inStr[i] / 100;
  106.       byte dozens = ((byte)inStr[i] - (hundreds*100)) / 10;
  107.       byte singles = (byte)inStr[i] - (hundreds*100) - (dozens*10);
  108.  
  109.       Keyboard.press(KEY_LEFT_ALT);
  110.       PressRelease((char)KEYPAD[hundreds], 5);
  111.       PressRelease((char)KEYPAD[dozens], 5);
  112.       PressRelease((char)KEYPAD[singles], 5);
  113.       Keyboard.releaseAll();
  114.       continue;
  115.     }
  116.  
  117.     /* SUBSTITUTION METHOD */
  118.     enc_index = GetKeyIndex(inStr.charAt(i), Encoding[ENCODING_BYTE_DESIRED]);
  119.     if(enc_index < 256)
  120.     {    
  121.       if(Encoding[ENCODING_BYTE_MODIFIER][enc_index] > 0)
  122.       {
  123.         Keyboard.press(Encoding[ENCODING_BYTE_MODIFIER][enc_index]);
  124.         delay(defaultCharDelay);
  125.       }
  126.       Keyboard.press(Encoding[ENCODING_BYTE_USED][enc_index]);
  127.       delay(defaultCharDelay);    
  128.     }
  129.     else
  130.     {
  131.       Keyboard.press(inStr.charAt(i));
  132.       delay(defaultCharDelay);    
  133.     }
  134.     Keyboard.releaseAll();
  135.   }
  136. }
  137.  
  138.  
  139.  
  140. void PressRelease(char c, byte timeDelay)
  141. {
  142.   Keyboard.press(c);
  143.   delay(timeDelay);
  144.   Keyboard.release(c);
  145. }
  146.  
  147. /*
  148. Exceptions are the letters that require different button being pressed in different lang settings
  149. (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)
  150. these exceptions are listed to make the typing process faster because using alt+numpad method for all the characters appears to be too slow
  151.  
  152. german - yz
  153. french - qamwz
  154. dutch - qamwz
  155. turkish - i
  156. azerbaijani - totally uncompatible
  157. */
  158.  
  159. #define EXCEPTIONS_SIZE 24
  160. char exceptions[EXCEPTIONS_SIZE] = {
  161.   'y','Y',
  162.   'z','Z',
  163.   'q','Q',
  164.   'a','A',
  165.   'm','M',
  166.   'w','W',
  167.   'i','I',
  168.   '0','1','2','3','4','5','6','7','8','9',
  169. };
  170.  
  171. bool IsException(char c)                    // check whether this character is one of these that have to be typed differently using other language settings
  172. {
  173.   for(byte i=0; i<EXCEPTIONS_SIZE; i++)
  174.   {
  175.     if(c == exceptions[i])
  176.     {
  177.       return true;
  178.     }
  179.   }
  180.   return false;
  181. }
  182.  
  183.  
  184. bool IsModifier(char c)                   // is key like shift, alt, "GUI" key, etc.
  185. {
  186.   byte b = (byte)c;
  187.   if((b >= 128 && b <=135) || (b >= 176 && b <=179) || (b >= 193 && b <=205) || (b >= 209 && b <=218))
  188.   {
  189.     return true;
  190.   }
  191.   return false;
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement