1 | static int forwardOneClick_windowSize = 11; // odd should look nice. Set to 1 for an invisible window |
2 | static int forwardOneClick_clickDelay = 0; // Delay in ms between closing window and forwarding click. 0 seems to work fine. |
3 | static int forwardOneClick_trackingSpeed = 10; // How often to move the window (ms) |
4 | |
5 | // onClick: voidfunc(Point, int) - 2nd parameter is button (1 to 3) |
6 | // if you make it a func and return false, click is not forwarded |
7 | static void forwardOneClick(final O onClick) {
|
8 | awtIfNecessary {
|
9 | final new JWindow window; |
10 | final int windowSize = forwardOneClick_windowSize; |
11 | window.setSize(windowSize, windowSize); |
12 | window.setVisible(true); |
13 | window.setAlwaysOnTop(true); |
14 | JPanel panel = singleColorPanel(Color.red); |
15 | window.setContentPane(panel); |
16 | revalidate(window); |
17 | final new Robot robot; |
18 | panel.addMouseListener(new MouseAdapter {
|
19 | public void mouseReleased(final MouseEvent e) {
|
20 | window.setVisible(false); |
21 | final int b = e.getButton(); |
22 | final int mod = |
23 | b == 1 ? InputEvent.BUTTON1_DOWN_MASK |
24 | : b == 2 ? InputEvent.BUTTON2_DOWN_MASK |
25 | : InputEvent.BUTTON3_DOWN_MASK; |
26 | final Point point = getMouseLocation(); |
27 | swingLater(forwardOneClick_clickDelay, r {
|
28 | if (isFalse(callF(onClick, point, b))) ret; |
29 | robot.mousePress(mod); |
30 | robot.mouseRelease(mod); |
31 | }); |
32 | } |
33 | }); |
34 | |
35 | swingEvery(window, forwardOneClick_trackingSpeed, r {
|
36 | Point p = getMouseLocation(); |
37 | window.setLocation(p.x-windowSize/2, p.y-windowSize/2); |
38 | }); |
39 | } |
40 | } |
Began life as a copy of #1005565
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1005566 |
| Snippet name: | forwardOneClick - track mouse pointer and record + forward one click |
| Eternal ID of this version: | #1005566/1 |
| Text MD5: | d61786bd99897ea3be8703f0825fb4ef |
| Author: | stefan |
| Category: | javax / gui |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-11-29 17:02:55 |
| Source code size: | 1633 bytes / 40 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 876 / 894 |
| Referenced in: | [show references] |