Facing some hiccups when running skl script from excel VBA

Asked by sami baig

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

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
sami baig
Solved:
Last query:
Last reply:
Revision history for this message
masuo (masuo-ohara) said :
#1

@RaiMan suggested hotkey as a solution in Question #662319.
https://answers.launchpad.net/sikuli/+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:
    popup("script01")

def script02:
    popup("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
    f.close()
    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")

Revision history for this message
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.

Revision history for this message
masuo (masuo-ohara) said :
#3

Try this codes.

[SikuliX script:]
def script01(event):
    popup("script01")

def script02(event):
    popup("script02")

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

[EXCEL VBA:]
Private Declare Sub Sleep Lib "Kernel32" (ByVal ms As Long)
Sub Button1_Click()
    SendKeys "^m"
    Sleep 5000

    SendKeys "^n"
    Sleep 5000
End Sub

[Operation:]
#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

Revision history for this message
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 ?

Revision history for this message
masuo (masuo-ohara) said :
#5

First of all, read document about Env.addHotkey().
http://sikulix-2014.readthedocs.io/en/latest/interaction.html#listening-to-global-hotkeys

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.

Revision history for this message
sami baig (gabbarmic) said :
#6

Thanks masuo you cleared my concept :)