Trouble passing string into type()

Asked by Brad Hagen on 2018-07-19

Hello Sikuli World,

Thanks for your generous help!

I have an app that uses 'hotkeys' (aka keyboard shortcuts) to perform various functions. In the sikuli IDE I can put the following in and it will open and close a panel on the app as expected.

type('P', Key.CTRL + Key.SHIFT)

When I try creating a string and using it as below it does not work. I have tried escaping the single quotes and that also did not work.

x = "'P', Key.CTRL + Key.SHIFT"
type(x)

My versions are:

sikuli 1.1.2
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) Client VM (build 25.161-b12, mixed mode, sharing)

I also get this but not always:

Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
at java.awt.Component.getLocationOnScreen_NoTreeLock(Unknown Source)
at java.awt.Component.getLocationOnScreen(Unknown Source)
at javax.swing.text.JTextComponent$InputMethodRequestsHandler.getTextLocation(Unknown Source)
at sun.awt.im.InputMethodContext.getTextLocation(Unknown Source)
at sun.awt.windows.WInputMethod$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)

at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2018-07-19
Last query:
2018-07-19
Last reply:
2018-07-19
Best RaiMan (raimund-hocke) said : #1

with type(keysequence, modifiers)

keysequence and modifiers are 2 function parameters, that cannot be packed into one string parameter.

If you want to do something like that, you have to make a wrapper function, that accepts a string and isolates the 2 parameters from there to give it then to type() internally.

BTW:
type('P', Key.CTRL + Key.SHIFT)

does not make sense, since the uppercase P already internally is used as lowercase p with a modifier SHIFT

so either
type('P', Key.CTRL)

or
type("p", Key.CTRL + Key.SHIFT) # recommended, since it is clearer

Brad Hagen (bhagen) said : #2

Thanks RaiMan, that solved my question.

Brad Hagen (bhagen) said : #3

Thanks RaiMan. Yes that makes perfect sense and now I wonder why I didn't realize it! I will give that a try. Another Sikuli happy customer!

Best Regards

Brad