Facing some hiccups when running skl script from excel VBA

Asked by sami baig on 2018-01-07

I am using below VB to launch script of sikuliX 1.1.2 from excel but it takes around 30 seconds to just execute the script and then script takes itself another seconds to fulfill the instruction. So is there any way to make this process very fast ?

VB Code:

Private Sub()

Dim dblRetVal As String

dblRetVal = Shell("java -jar E:\SikuliX1.1.2\sikulix.jar -r D:\ProjectKiosk\Scripts\test2.sikuli —a1 a2 a3", vbHide)

End Sub()

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
sami baig
Last query:
Last reply:
masuo (masuo-ohara) said : #1

@RaiMan suggested hotkey as a solution in Question #662319.

Find out a short cut key not used in EXCEL.
Define hotkey handler function that will be called by the short cut key,in the SikuliX script.
This script needs to wait forever for input. In other words this script must not be terminated.

Run SikuliX script before running EXCEL VBA.
Then send the short cut key in EXCEL VBA.

[example codes]
This codes shown here is only an idea, not complete.
def script01:

def script02:

#-----read linkage file between EXCEL VBA and SikuliX script
def read_info():
    info = []
    f = open('C:\tmp\info.txt', 'r')
    # append to "info" from file
    return info

#-----hotkey handler
def hotley_handler(event):
    info = read_info()
    # branch to script01 or script02 by info

#-----Main script
Env.addHotkey("m", KeyModifier.CTRL, hotley_handler)
popup("Click [OK] to exit")

sami baig (gabbarmic) said : #2

Thanks masuo, your response is worth considering but please give some more examples or web link where I can learn and create my scripts accordingly.

masuo (masuo-ohara) said : #3

Try this codes.

[SikuliX script:]
def script01(event):

def script02(event):

Env.addHotkey("m", KeyModifier.CTRL, script01)
Env.addHotkey("n", KeyModifier.CTRL, script02)
popup("Click [OK] to exit")

Private Declare Sub Sleep Lib "Kernel32" (ByVal ms As Long)
Sub Button1_Click()
    SendKeys "^m"
    Sleep 5000

    SendKeys "^n"
    Sleep 5000
End Sub

#1 Run SikuliX script, popup "Click [OK] to exit" appear
#2 Click Button1 on EXCEL
#3 popup "script01" appear
#4 click [OK] of popup #3
#5 popup "script02" appear
#6 click [OK] of popup #5
#7 click [OK] of popup #1

sami baig (gabbarmic) said : #4

Are you calling modules through this script by def (event) by module name script01 and script02 ? and what does mean of "Env.addHotkey("m", KeyModifier.CTRL, script01) " function ?

masuo (masuo-ohara) said : #5

First of all, read document about Env.addHotkey().

Define hotkey handler function "script01" that will be called by CTRL + "m" keys, in the SikuliX script.
Env.addHotkey("m", KeyModifier.CTRL, script01)

Send CTRL + "m" keys, in EXCEL VBA.
SendKeys "^m"

When you click Button1 on EXECL, CTRL + "m" keys are sent and function "script01" is called.

sami baig (gabbarmic) said : #6

Thanks masuo you cleared my concept :)