Cannot type slash character. This slash: "/" --- workaround: alt + numpad

Asked by André Pfitzner

************** workaround
Found the best solution. Universal on all Windows systems is alt + numpad (from comment #7)

# So for Slash
def typeSlash():
    keyDown(Key.ALT)
    type(Key.NUM4+Key.NUM7)
    keyUp()

#or like this:
string = 'jan/2017'
string = string.replace('/', Key.DIVIDE)
type(string)

---------------------------------------------
When I issue the command on the line 3 of my script:
    type("/")
The Sikuli IDE does not send the slash character ("/") and throw the following error:

[sikuli] [Error] source lineNo: 3
[sikuli] [Error] Traceback (innermost last):
  File "C:\DOCUME~1\ADMINI~1\CONFIG~1\Temp\sikuli-tmp8004614922768274155.py", line 3, in ?
  File "C:\Arquivos de programas\Sikuli\sikuli-ide-full.jar\Lib/python/edu/mit/csail/uid/Sikuli.py", line 514, in type
 at sun.awt.windows.WRobotPeer.keyPress(Native Method)
 at java.awt.Robot.keyPress(Unknown Source)
 at edu.mit.csail.uid.SikuliScript.doType(SikuliScript.java:465)
 at edu.mit.csail.uid.SikuliScript.doType(SikuliScript.java:457)
 at edu.mit.csail.uid.SikuliScript.type_ch(SikuliScript.java:569)
 at edu.mit.csail.uid.SikuliScript.type(SikuliScript.java:626)
 at edu.mit.csail.uid.SikuliScript.type(SikuliScript.java:446)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Invalid key code

Thanks for the attention and congratulation for this very useful tools :)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
André Pfitzner
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

This is not really a bug, since per definition the type() internally uses the american keyboard layout.

On my german Mac keyboard e.g. type("/") produces a - (hyphen). this is the corresponding key on the US keyboard.

You have 2 options:

1. use paste() instead of type() if the target of your typing is some kind of input field. it uses internally the clipboard and in this cases always produces the correct result. You can intermix paste() (typing text) and type() (pressing special keys).

2. find out, what would be produced with an US layout, if you press the key, that produces / with your actual layout. use this instead. (e.g. in my german example type("&") actually produces "/" or type("7", KEY_SHIFT)).

Revision history for this message
RaiMan (raimund-hocke) said :
#2

the type() problem with non-US keyboard layout is already in Progress
(https://bugs.launchpad.net/sikuli/+bug/511740)

Revision history for this message
mcklaw (victor-martinez-conte) said :
#3

Hi, i had the same behavior trying to "type" an URL (and some paths). Paste worked like a charm!

Revision history for this message
André Pfitzner (andrepfitzner) said :
#4

Thanks. This works fine.
I am closing this bug because the workaround with "paste" works on vast majority of situations, and because the other bug reported is less specific: https://bugs.launchpad.net/sikuli/+bug/511740

But I hope the send became functional with all types of keyboard layouts.

Thanks :)

Revision history for this message
angelo (angelo-j) said :
#5

@Raimund Will the keyboard layout be settable in the new 1.1.0 release?

Revision history for this message
RaiMan (raimund-hocke) said :
#6

@Angelo
yes a solution for the type problem is on the list for version 2

A workaround always is to switch to the US-layout for the time of script run (there might be commands available to do that) and then switch back to your local layout.

Revision history for this message
Fritz (lugler) said :
#7

Found the best solution. Universal on all Windows systems is alt + numpad.
So for Slash:

def typeSlash():
    keyDown(Key.ALT)
    type(Key.NUM4+Key.NUM7)
    keyUp()

Revision history for this message
FranciscoLima (faclsp) said :
#8

Hello,
Some applications do not accept the ALT + 47 command.
In this case, you can solve using Key.DIVIDER:

Example:

string = 'jan/2017'
string = string.replace('/', Key.DIVIDE)
type(string)