Author Topic: Keyboard non-ASCII characters command  (Read 5421 times)

yo2ldk

  • Newbie
  • *
  • Posts: 6
Keyboard non-ASCII characters command
« on: November 29, 2015, 12:16:21 pm »
 Hi all,

 I need to make a sketch for Two buttons, who send via USB commands like KEYSTROKES CTRL + LEFT GUI or CTRL + ALT + DELETE.
   this is what I try but no luck to compile, please some advice

#include <DigiKeyboard.h>
#include <oddebug.h>
#include <osccal.h>
#include <osctune.h>
#include <scancode-ascii-table.h>
#include <usbconfig-prototype.h>
#include <usbconfig.h>
#include <usbdrv.h>
#include <usbportability.h>

#define KEYCODE_MOD_LEFT_CONTROL    0x01
#define KEYCODE_MOD_LEFT_SHIFT      0x02
#define KEYCODE_MOD_LEFT_ALT        0x04
#define KEYCODE_MOD_LEFT_GUI        0x08   
#define KEYCODE_MOD_RIGHT_CONTROL   0x10
#define KEYCODE_MOD_RIGHT_SHIFT     0x20
#define KEYCODE_MOD_RIGHT_ALT       0x40
#define KEYCODE_MOD_RIGHT_GUI       0x80


uint8_t button1 = 0;
uint8_t button2 = 2;

// We'll assume that your button inputs are normally LOW, and go to HIGH when pressed
uint8_t value1 = HIGH;
uint8_t value2 = HIGH;

void setup() {
 
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
}

void loop() {
 
  value1 = digitalRead(button1);
  value2 = digitalRead(button2);

  if (value1 == LOW) {
    DigiKeyboard.sendKeyStroke (KEYCODE_MOD_LEFT_CONTROL,KEYCODE_RIGHT_GUI)
   ;
  }

  if (value2 == LOW) {
    DigiKeyboard.sendKeyStroke(KEYCODE_MOD_LEFT_ALT|KEYCODE_MOD_LEFT_CONTROL,KEYCODE_DELETE);
  }
 
  DigiKeyboard.delay(10);
   }

Ralf

  • Guest
Re: Keyboard non-ASCII characters command
« Reply #1 on: December 01, 2015, 05:19:15 am »
Hi Alex,

the table in Digikeyboard.h is pretty incomplete, KEYCODE_RIGHT_GUI and KEYCODE_DELETE are not defined there. You could try to use the decimal numbers (I'm not sure, I think it's  42 and 231) directly.

Ralf

yo2ldk

  • Newbie
  • *
  • Posts: 6
Re: Keyboard non-ASCII characters command
« Reply #2 on: December 02, 2015, 12:30:22 am »
 Thank you Ralph for reply and help,

  I tried that with Hex and Dec.and I receive error "...was not declared in this scope"
can we modify the .h file to declare some key ?
but also there is:

#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)

and I don't know how to declare it becaus is not a valu hex or dec, is  (1<<0)...  what that means   :-\


Ralf

  • Guest
Re: Keyboard non-ASCII characters command
« Reply #3 on: December 02, 2015, 01:53:30 am »
Hi Alex,

it's C-style bit shifting,

Code: [Select]
#define MOD_GUI_RIGHT       (1<<7)

means: put a "1" into the variable and shift it 7 times left. So it's the same as your

Code: [Select]
#define KEYCODE_MOD_RIGHT_GUI       0x80


To make it easier, you may use the decimal values (I did not try it, hope it works it this way)

Code: [Select]
DigiKeyboard.sendKeyStroke (1,231)
should be ctrl + left gui and

Code: [Select]
DigiKeyboard.sendKeyStroke (1+4,42)
hopefully is crtl + alt + delete

73,
Ralf


yo2ldk

  • Newbie
  • *
  • Posts: 6
Re: Keyboard non-ASCII characters command
« Reply #4 on: December 02, 2015, 10:10:42 am »
not work with that, I use Trinket library now, is really good, but it seems is some problem with windows 10 and driver
 I manage only one command, CTRL +V for test and now compiles without problems,
but when i act over button, this not execute,instead that, somehow my laptop keyboard was "lock" with ALT taste
( and that is not mentioned at all in sketch..)
very strange anyway, i keep digging.

 me best regards and 73 Ralph !

Ralf

  • Guest
Re: Keyboard non-ASCII characters command
« Reply #5 on: December 02, 2015, 12:42:59 pm »
Hi Alex,

I made some mistakes. The character has to be in the first place, the modifier in the second place.

And there are several keys for "delete", I took the wrong one.

ctr + alt + delete is:

Code: [Select]
DigiKeyboard.sendKeyStroke (76,1+4)

The windows key is somewhat weird. Left Gui key is dec. 227, but with (227,0) nothing happens. But with

Code: [Select]
DigiKeyboard.sendKeyStroke (227,8)

the Windows menu comes up and disappears again.


Your code sends not only one character, but multiple, as long as the button is pressed. It should only send one character, until the button is released and pressed again.

73,
Ralf

PS: There is another issue in your code: If you do not use external pullup resistors, you should activate the internal pullups:

Code: [Select]
void setup() {
 
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
//activate internal pullups of the ATtiny85:
  digitalWrite(button1,1);
  digitalWrite(button2,1);
}
« Last Edit: December 02, 2015, 12:57:53 pm by Ralf »

yo2ldk

  • Newbie
  • *
  • Posts: 6
Re: Keyboard non-ASCII characters command
« Reply #6 on: December 02, 2015, 02:04:30 pm »
I use external pull up 10k resistor, I think now I am on a good way,
making some changes to  Digikeyboard h file to recognize modifier keys
thank you for your time and support!
 when all is done, coming back with news :)