Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #1005565 // 1-Pixel Window Mouse Tracking & Forwarding [works, just not for dragging]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (2994L/19K).

!7

static int windowSize = 11; // odd should look nice. Set to 1 for an invisible window
static int clickDelay = 0; // Delay in ms between closing window and forwarding click. 0 seems to work fine.
static int trackingSpeed = 10; // How often to move the window (ms)

p {
  final new JWindow window;
  window.setSize(windowSize, windowSize);
  window.setVisible(true);
  window.setAlwaysOnTop(true);
  JPanel panel = singleColorPanel(Color.red);
  window.setContentPane(panel);
  revalidate(window);
  final new Robot robot;
  panel.addMouseListener(new MouseAdapter {
    // public void mousePressed(final MouseEvent e) {}
    
    public void mouseReleased(final MouseEvent e) {
      print("release! " + e);
      window.setVisible(false);
      int b = e.getButton();
      final int mod =
        b == 1 ? InputEvent.BUTTON1_DOWN_MASK
        : b == 2 ? InputEvent.BUTTON2_DOWN_MASK
        : InputEvent.BUTTON3_DOWN_MASK;
      swingLater(clickDelay, r {
        print("clicking " + mod);
        robot.mousePress(mod);
        robot.mouseRelease(mod);
      });
    }
  });
  
  swingEvery(window, trackingSpeed, r {
    Point p = getMouseLocation();
    window.setLocation(p.x-windowSize/2, p.y-windowSize/2);
    //print("moving");
  });
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, hfqflyfjmcnm, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005565
Snippet name: 1-Pixel Window Mouse Tracking & Forwarding [works, just not for dragging]
Eternal ID of this version: #1005565/2
Text MD5: d5553bd27682e57e0a90d098ff8fdb12
Transpilation MD5: df12aadad53154425cd931df708f43d6
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-10-31 12:49:17
Source code size: 1287 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 1717 / 2621
Version history: 1 change(s)
Referenced in: #1005566 - forwardOneClick - track mouse pointer and record + forward one click