Closed rahmanshaber closed 2 years ago
Just a silly question, how do you get those symbols with hardware keyboard? hint: you have SHIFT key
I know that, but i don't want to hold the shift key to use the symbols. i want them directly.
You dont have to hold shift key, you have to send it as modifier. What you are doing is wrong, because you dont send modifier keys, like SHIFT or CTRL, like normal keys. They are modifiers.
I see you are sending left CTRL and you can add SHIFT with logic or |
to it, but dont add it to key code.
This is wrong #define KEYS_AT HID_KEY_2|KEYBOARD_MODIFIER_LEFTSHIFT /* @ */
SHIFT has to be sent togheter with capital letters or with symbols.
are you talking about this? but this does not work for all the keys
static void processKeys( void )
{
if( !Keyboard.getKeys() ) return;
// disable the keyboard when display is off
if( !digitalRead( POWER_LCD ) ) return;
int i;
for( i = 0; i < LIST_MAX; i++ )
{
if( !Keyboard.key[i].stateChanged ) continue;
uint8_t key = mapKey( Keyboard.key[i].kchar );
if( key == KMAP_SWITCH || key == HARDWARE_TEST || key == KMOUSE_LEFT ||
key == KMOUSE_RIGHT || key == EXPANSION_SWITCH || key == LCD_SWITCH ) continue;
switch( Keyboard.key[i].kstate )
{
case PRESSED:
if( key == HID_KEY_CONTROL_LEFT )
{
HIDdevice.sendPress( 0, KEYBOARD_MODIFIER_LEFTCTRL );
modifierKey = KEYBOARD_MODIFIER_LEFTCTRL;
}
else if( key == HID_KEY_GUI_LEFT )
{
HIDdevice.sendPress( 0, KEYBOARD_MODIFIER_LEFTGUI );
modifierKey = KEYBOARD_MODIFIER_LEFTCTRL;
}
else
{
if (key & KEYBOARD_MODIFIER_LEFTSHIFT) {
key ^= KEYBOARD_MODIFIER_LEFTSHIFT;
HIDdevice.sendPress( key, KEYBOARD_MODIFIER_LEFTSHIFT );
} else {
HIDdevice.sendPress( key, modifierKey );
modifierKey = 0;
}
}
break;
case RELEASED:
HIDdevice.sendRelease();
modifierKey = 0;
break;
}
}
}
Which keys are not working? Maybe you have on your PC installed keyboard layout which is not compatible? https://github.com/chegewara/EspTinyUSB/blob/master/src/hidkeylayout.h#L61-L71
KEYS_EXCL, KEYS_AT, KEYS_HASH, KEYS_DOLLAR, KEYS_PERCENT, KEYS_CARET, KEYS_AMP, KEYS_ASTERISK, KEYS_LRBRACKET, KEYS_RRBRACKET,
result YZ#$#$&&
i typed them in left to right order
And i told you, this is not the correct definition:
#define KEYS_EXCL HID_KEY_1|KEYBOARD_MODIFIER_LEFTSHIFT /* ! */
#define KEYS_AT HID_KEY_2|KEYBOARD_MODIFIER_LEFTSHIFT /* @ */
#define KEYS_HASH HID_KEY_3|KEYBOARD_MODIFIER_LEFTSHIFT /* # */
#define KEYS_DOLLAR HID_KEY_4|KEYBOARD_MODIFIER_LEFTSHIFT /* $ */
#define KEYS_PERCENT HID_KEY_5|KEYBOARD_MODIFIER_LEFTSHIFT /* % */
#define KEYS_CARET HID_KEY_6|KEYBOARD_MODIFIER_LEFTSHIFT /* ^ */
#define KEYS_AMP HID_KEY_7|KEYBOARD_MODIFIER_LEFTSHIFT /* & */
#define KEYS_ASTERISK HID_KEY_8|KEYBOARD_MODIFIER_LEFTSHIFT /* * */
#define KEYS_LRBRACKET HID_KEY_9|KEYBOARD_MODIFIER_LEFTSHIFT /*( */
#define KEYS_RRBRACKET HID_KEY_0|KEYBOARD_MODIFIER_LEFTSHIFT /* ) */
i can't spare a button to use at a shift, so one can hold it and press the number to get the symbols.
Can you give me correct way to define the combination?
or just give me an example where pressing one button does a key combination with.
like ctrl +p for paste
You dont have to use separate pin or make hardware modifications, just use code correctly. You can use example code to test if you will get correct output from:
HIDdevice.sendString("!@#$%^&*()");
This is close to what you need, but you cant modify key
value:
HIDdevice.sendPress( key, KEYBOARD_MODIFIER_LEFTSHIFT );
as second parameter is telling OS that you have pressed shift and/or ctrl and other special keys.
example of CTRL + P:
HIDdevice.sendPress( 'p', KEYBOARD_MODIFIER_CTRL );
You can also use sendChar
to send any of !@#$%^&*()
tinyUSB don't have some symbols accessible directly. In order to get $%^&?" and other symbols i used this method but can get it working. if i press the keys i get only numbers. What the issue might be?