Global keys not working properly on script

Asked by sami baig on 2018-01-26

I am using below codes to call def() event via sikuliX but while running this event, I click excel macro button to call it's script and even though script also running but it skips to click on "Chrome.png".

SikuliX Codes:
def Primary(event):
    find()
    click(Pattern().targetOffset(61,2))
    type("g",KEY_CTRL)
    type(Key.BACKSPACE)
    type("H36" + Key.ENTER)
    type(Key.LEFT)
    type("c",KEY_CTRL)
    find(Chrome.png)
    click(Chrome.png) # <------------------------------------------------------------Skip on this line
    while not exists():
        type(Key.PAGE_UP*3)
    click()
    click(Pattern().targetOffset(-83,5))
    type("v",KEY_CTRL)
    type(Key.TAB + Key.ENTER)
    find()
    click()
    type("g",KEY_CTRL)
    type(Key.BACKSPACE)
    type("H46" + Key.ENTER)
    type(Key.LEFT)
    type("c",KEY_CTRL)
    find()
    click(Chrome.png) # <--Switch
    click(Chrome.png)
    type("a",KEY_CTRL)
    type(Key.BACKSPACE)
    type("v",KEY_CTRL)
    find()
    click() # <--Switch
    type("g",KEY_CTRL)
    type(Key.BACKSPACE)
    type("H51" + Key.ENTER)
    type(Key.LEFT)
    type("c",KEY_CTRL)
    find(Chrome.png)
    click(Chrome.png) # <--Switch
    if exists():
        click()
        type("v",KEY_CTRL)
        type(Key.TAB*11)
        #type(Key.PAGE_DOWN)
        #click("1514380908917.png")
        type(Key.DOWN*40)
        type(Key.UP*17)
        type(Key.TAB)
        wait(1)
        type("a",KEY_CTRL)
        type(Key.BACKSPACE)
    else:
        click()
        type("a",KEY_CTRL)
        type(Key.BACKSPACE)
        type("v",KEY_CTRL)
        type(Key.PAGE_DOWN)
        wait(1)
        click()
        type(Key.DOWN*40)
        type(Key.UP*17)
        type(Key.TAB)
        wait(1)
        type("a",KEY_CTRL)
        type(Key.BACKSPACE)
    popup("Click has done!")
Env.addHotkey("n", KeyModifier.CTRL + KeyModifier.ALT , Primary)
while True:
    wait(1)

Excel VB:
Private Declare Sub Sleep Lib "Kernel32" (ByVal ms As Long)
Sub Button1_Click()
    SendKeys "^%n"
    Sleep 5000
End Sub

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-01-26
Last reply:
2018-01-27
RaiMan (raimund-hocke) said : #1

I guess, after the click you have to insert a short wait() (try wait(0.3)) to give the GUI some time to react.

Or wait for something that should be visible, after Chrome.png is clicked and ready to get the key strokes.

BTW: this looks odd:

# this is
  find(Chrome.png)
  click(Chrome.png)
# the same as
  click(Chrome.png)

  while not exists(???....???): # what are you looking for?
        type(Key.PAGE_UP*3)
  click() # clicks the last match found on SCREEN - is it what you mean?

Can you help with this problem?

Provide an answer of your own, or ask sami baig for more information if necessary.

To post a message you must log in.