Robotjs: typeString and keyTap write semicolon(;) for colon(:) on Ubuntu(vbox)

Created on 12 Apr 2017  路  8Comments  路  Source: octalmage/robotjs

typeString and keyTap write semicolon(;) for colon(:) on Ubuntu(vbox)

Most helpful comment

Very late here, but I ran into this issue recently and solved it with the following snippet of code:

const MATCH_REGEX = /[~!@#\$%\^&*()_+{}|:"<>?]/;
let str = 'test string ~!@#$%^&*()_+{}:"<>?';

// minimize delay between robot keyboard calls
robot.setKeyboardDelay(1);

while (str) {
   let match = str.match(MATCH_REGEX);

   if (match) {
      robot.typeString(str.substr(0, match['index']));
      robot.keyTap(match[0], ['shift']);
      str = str.substr(match['index']+1);
   }
   else {
      robot.typeString(str);
      str = null;
   }
}

Not a perfect or even a great solution, but this will do for now...

All 8 comments

Same here on Raspberry Pi 3 (Raspbian Jessie)

Same here on Linux Mint 18.2 (not running in a virtual machine)

edit: seems to be special characters which require shift to be held down

The following code

var robot = require("robotjs");
robot.typeString("This is a test -- ~ ! @ # $ % ^ & * ( ) _ + ? | -- end");

Produces the following output

This is a test -- ` 1 2 3 4 5 6 7 8 ( ) - = / \ -- end

Same issue as this -- https://github.com/octalmage/robotjs/issues/324

Same issue, linux mint

Same issue on Ubuntu 16.04 LTS, works as intended on my Mac. I need this for a product demo in a few days -- is there anything I can do to help resolve this more quickly?

Very late here, but I ran into this issue recently and solved it with the following snippet of code:

const MATCH_REGEX = /[~!@#\$%\^&*()_+{}|:"<>?]/;
let str = 'test string ~!@#$%^&*()_+{}:"<>?';

// minimize delay between robot keyboard calls
robot.setKeyboardDelay(1);

while (str) {
   let match = str.match(MATCH_REGEX);

   if (match) {
      robot.typeString(str.substr(0, match['index']));
      robot.keyTap(match[0], ['shift']);
      str = str.substr(match['index']+1);
   }
   else {
      robot.typeString(str);
      str = null;
   }
}

Not a perfect or even a great solution, but this will do for now...

When I write the output of the vars:
https://github.com/octalmage/robotjs/blob/e99b961a1f20c32dc8d1b6e7647f90d555422426/src/keypress.c#L243

Output logging from

String: Test@2test
c: T, 84, 0x24  >> n: 36 
c: e, 101, 0x35  >> n: 53 
c: s, 115, 0x43  >> n: 67 
c: t, 116, 0x44  >> n: 68 
c: @, 64, 0x10  >> n: 16 
c: 2, 50, 0x2  >> n: 2 
c: t, 116, 0x44  >> n: 68 
c: e, 101, 0x35  >> n: 53 
c: s, 115, 0x43  >> n: 67 
c: t, 116, 0x44  >> n: 68 

Now it will call toggleUniKey()
https://github.com/octalmage/robotjs/blob/e99b961a1f20c32dc8d1b6e7647f90d555422426/src/keypress.c#L234

When we call: toggleKey(c, down, true) all special chars like '@' will be there.. So we have to filter the special chars and set the boolean from toggleKey

Sorry, I'm not a C programmer, so I have no idea what I'm doing :

So maybe Implement something like:

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

int main () {
  char string[55] ="!@#$%^&*()_+";
  char *p;
  p = strchr (string,'%');
  int index = (p - string + 1);
  bool isFound = index >= 0;
  printf ("Character i is found at position %d\n", index);
  if(isFound) {
    printf ("Yes I'm special\n");
  } else {
    printf ("NO I'm NOT\n");
  }
  return(0);
}

Replacing:
https://github.com/octalmage/robotjs/blob/e99b961a1f20c32dc8d1b6e7647f90d555422426/src/keypress.c#L280-L281

with:

          char *p;
          char specialChars[55] ="!@#$%^&*()_+";
          p = strchr(specialChars,c);
          int index = (p - specialChars + 1);
          bool isFound = index >= 0;
          printf ("Character i is found at position %d\n", index);
          if(isFound) {
            printf ("Yes I'm special\n");
            toggleKey(n, true, true);
            toggleKey(n, false, true);
          } else {
            toggleUniKey(n, true);
            toggleUniKey(n, false);
            printf ("NO I'm NOT\n");
          }

It seems it can type some chars now.

Very late here, but I ran into this issue recently and solved it with the following snippet of code:

const MATCH_REGEX = /[~!@#\$%\^&*()_+{}|:"<>?]/;
let str = 'test string ~!@#$%^&*()_+{}:"<>?';

// minimize delay between robot keyboard calls
robot.setKeyboardDelay(1);

while (str) {
   let match = str.match(MATCH_REGEX);

   if (match) {
      robot.typeString(str.substr(0, match['index']));
      robot.keyTap(match[0], ['shift']);
      str = str.substr(match['index']+1);
   }
   else {
      robot.typeString(str);
      str = null;
   }
}

Not a perfect or even a great solution, but this will do for now...

Thanks for the code for me is working great just put typeStringDelayed because my ubuntu missed the chars

Thank you, looks like it has been solved :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Androiderr picture Androiderr  路  4Comments

poojas2288 picture poojas2288  路  5Comments

saghul picture saghul  路  6Comments

lmnyx picture lmnyx  路  5Comments

IChocolateKapa picture IChocolateKapa  路  12Comments