[Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use

2014-09-08 Thread Max
New question #254203 on Sikuli:
https://answers.launchpad.net/sikuli/+question/254203

I'm trying to write a java program that can listen when a user copies a text 
like this:

String key = "c";
int modifiers = KeyModifier.CTRL;

HotkeyListener listener = new HotkeyListener() {
@Override
public void hotkeyPressed(HotkeyEvent hotkeyEvent) {
copyListener.executeCopy();
}
};

HotkeyManager.getInstance().addHotkey(key, modifiers, listener);

My problem is that this code overrides the global hotkey so that nothing is 
actually copied to clipboard when I press ctrl + c (when I get result from 
clipboard I only get what I copied before running this program, it works fine 
when I'm not using this hotkeylistener though). Is it possible to let the user 
copy text with ctrl + c and just listen to the event without intercepting it, 
or somehow place the selected text in clipboard?

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use

2014-09-08 Thread RaiMan
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

Status: Open => Answered

RaiMan proposed the following answer:
It is always very interesting, to see, how the usage of Sikuli sometimes
narrows the imagination of possible solutions.

Since you already are on the Java level, I just googled: java clipboard
one of the suggestions was
java clipboard listener

... and this is the topmost result (of course on stack overflow ;-)
http://stackoverflow.com/questions/14226064/calling-a-method-when-content-of-clipboard-is-changed

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use

2014-09-08 Thread Max
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

Status: Answered => Open

Max is still having a problem:
Lol that's stupid of me, but I also realized that I will need a way to
copy code anyways. Because I want two different ways of copying with two
different key combinations, can I throw a ctrl + c event in Sikuli to
copy a text (or do it another way)? (I'm extremely new to Sikuli)

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use

2014-09-08 Thread RaiMan
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

Status: Open => Answered

RaiMan proposed the following answer:
for copying some text programmatically we have paste() (internally this
puts something on the clipboard and then issues a ctrl-c)

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use

2014-09-08 Thread Max
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

Status: Answered => Open

Max is still having a problem:
Which class is that in?

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use

2014-09-08 Thread RaiMan
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

Status: Open => Answered

RaiMan proposed the following answer:
it is a region function, like click, find and all these features.

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use

2014-09-08 Thread Max
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

Status: Answered => Solved

Max confirmed that the question is solved:
I ended up using java.awt.Robot, works as I'd like it to now. Thanks for
the answers though!

final HotkeyListener listener = new HotkeyListener() {
@Override
public void hotkeyPressed(HotkeyEvent hotkeyEvent) {
try {
HotkeyManager.getInstance().removeHotkey(key, modifiers);
Robot robot = new Robot();
robot.keyPress(KeyEvent.CTRL_DOWN_MASK);
robot.delay(100);
robot.keyPress(KeyEvent.VK_C);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_C);
robot.delay(100);
robot.keyRelease(KeyEvent.CTRL_DOWN_MASK);
robot.delay(1000);
copyListener.executeCopy();
HotkeyManager.getInstance().addHotkey(key, modifiers, this);
} catch (AWTException e) {
e.printStackTrace();
}
}
};

A bit tricky playing around with the delays, but it doesn't need to be
fast so it's fine

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use

2014-09-08 Thread RaiMan
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

RaiMan posted a new comment:
have you tried

type("c", Key.CTRL)

before experimenting with the Robot class yourself?

If you need to handle individual keys, we have

key.Down(Key.CTRL)
wait(100)
type("c")
keyUp()

both solutions  would replace the sequence
Robot robot = new Robot();
robot.keyPress(KeyEvent.CTRL_DOWN_MASK);
robot.delay(100);
robot.keyPress(KeyEvent.VK_C);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_C);
robot.delay(100);
robot.keyRelease(KeyEvent.CTRL_DOWN_MASK);

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use (ctrl-c)

2014-09-08 Thread RaiMan
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

RaiMan posted a new comment:
BTW: what system are you working on?

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use (ctrl-c)

2014-09-08 Thread RaiMan
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

Summary changed to:
Hotkey Listener overrides hotkey use (ctrl-c)

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use (ctrl-c)

2014-09-09 Thread Max
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

Max posted a new comment:
I tried the first one first, didn't work so well, I will check again
with both solutions when I get back from work or maybe at lunch. It
could possibly be a little problematic because I'm in my example
actually physically pressing ctrl + c the same time, I think that's
maybe why the delays and timing seem so critical. I'm on Ubuntu 14.04.

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use (ctrl-c)

2014-09-09 Thread RaiMan
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

RaiMan posted a new comment:
ok understood.

then this should help:

wait(0.3f); // or an even higher value 
type("c", Key.CTRL)

or
wait(0.3f); // or an even higher value 
key.Down(Key.CTRL)
wait(0.1f)
type("c")
keyUp()

I doubt that the "inner" extra waits are needed.

sorry for the wrong wait values: a float as seconds is needed.

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


Re: [Sikuli-driver] [Question #254203]: Hotkey Listener overrides hotkey use (ctrl-c)

2014-09-09 Thread Max
Question #254203 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/254203

Max posted a new comment:
Wow.. I don't know why I thought it didn't work, it works perfectly,
better than my robot solution (using your first suggestion). Maybe I
used the wait function wrong the first time or something. Thanks a lot!

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp