JAVA API : hotkey working just first time?

Asked by Dado on 2018-11-09

I'm trying to stop a loop in my app using a global hotkey .
This is the code for the hotkey I'm using:

        HotkeyListener hk_CTRL_F1 = new HotkeyListener()
        {
            @Override
            public void hotkeyPressed(HotkeyEvent e) {
                running=false;
            }
        };

        HotkeyManager.getInstance().addHotkey(Key.F1, KeyModifier.CTRL, hk_CTRL_F1 );

then in my loop I'ìm checking for running==true, else it should end.
I'm running my app from intellij IDEA ide, it works fine the fisrt time, then if I run it again the hotkey is not working anymore and the loop goes on forever.

if I close the IDE , repon and start it again , the hotkey works fine again (the first time).

I tried also to remove the hotkey after the loop, before closing the app like this:

HotkeyManager.getInstance().removeHotkey(Key.F1,KeyModifier.CTRL);

but this does not help.

Any idea? is it a bug?

thanks

Question information

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

Offline til Nov 20th
Surely not the intended use
You have to wait or find out

masuo (masuo-ohara) said : #2

@Dado

Variable "running" is global ?
By popup window you can confirm hotkey is available .

This code works as expected.
[example as python:]
flag = True
def handler(event):
    global flag
    popup("Hotkey!")
    flag = False

Env.addHotkey(Key.F1,KeyModifier.CTRL,handler)

while True:
    popup("[OK]")
    if flag == False:
        break

Dado (dadotc) said : #3

hi masuo, thanks, yes the variable is global, and I'm sure the hotkey is available because sometimes it works.
I'll do some more test to try understand what could be

Can you help with this problem?

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

To post a message you must log in.