← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #193287]: Problems when running javaw.exe or java.exe with hidden console

 

Question #193287 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/193287

    Status: Open => Answered

RaiMan proposed the following answer:
I tested on my Win7-32
I had no problems in any run situation (using javaw directly as in --1. or as one command in another command/batch file)

So you have to be more specific with your problem description.

--1. javaw.exe
I made a shortcut on the desktop containing as link target:
C:\Windows\System32\javaw.exe -jar "C:\Program Files\Sikuli X\sikuli-script.jar"

taking a .sikuli folder and dropping it on the link symbol runs the
script.

--2. Sikuli Hotkeys
If you want to use this feature, you need some loop, to keep the Sikuli script alive (you have this).
If you have implemented some ending feature (I always define a alt-ctrl-x hot key, that lets my script end).
If you use this, you have to add an exit() to the end of the script.
Otherwise, you have to kill the javaw process.

BTW: while Sikuli is active in a hotkey handler (e.g. waiting for
images) the hotkey handling is blocked (no other hotkeys accepted until
the handler terminates).

this is my typical template:

popup("Hello from Sikuli")

isExit = False

def hk_x(e):
    global isExit
    isExit = True

def hk_y(e):
    if isExit: 
        return
    # some code here

Env.addHotkey("x", KeyModifier.CTRL+KeyModifier.ALT, hk_x)
Env.addHotkey("y", KeyModifier.CTRL+KeyModifier.ALT, hk_y)

while not isExit:
    wait(1)

popup("Sikuli says GoodBye")

# not really necessary
Env.removeHotkey("x", KeyModifier.CTRL+KeyModifier.ALT)
Env.removeHotkey("y", KeyModifier.CTRL+KeyModifier.ALT)

exit()

--3. your situation
I built a test case to simulate your situation:
- made a handler for alt-ctrl-y
- wait for something to come up
- wait for it to vanish
- wait again for something
- leave the handler

the coming up and vanishing I manually simulated with an
InternetExplorer window.

the handler:

def hk_y(e):
    if isExit: 
        return
    wait(img, FOREVER)
    getLastMatch().highlight(2)
    wait(2)
    waitVanish(img, FOREVER)    
    wait(img, FOREVER)
    App.focusedWindow().highlight(2)
    popup("Hello, Sikuli alive!")

You said, that you use AutoHotkey, to handle the application window. 
Since I know, that with the second appearance the window is frontmost (I did that manually ;-), I can use 
App.focusedWindow()
to get the region of the app window.

If this is the fact for your situation too, you can replace your
setControlBarRegion()
with something like:
setROI(App.focusedWindow())

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.