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

38
LINES

< > BotCompany Repo | #1005823 // Continually move mouse to centroid; block for 1 second on interference

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

Libraryless. Click here for Pure Java version (4944L/34K/114K).

1  
!752
2  
3  
static int viewSize = 21;
4  
static int interval = 100;
5  
static float speed = 0.3f;
6  
static float minOffset = 0f; // 0.5f; // offset needed to move at all
7  
volatile sbool useDarkCentroid = false;
8  
9  
static JCheckBox cbDark;
10  
11  
p {
12  
  awt {
13  
    showControls(jcenteredLine(
14  
      cbDark = jCheckBox("Focus on dark things", useDarkCentroid, r {
15  
        useDarkCentroid = cbDark.isSelected();
16  
      })
17  
    ));
18  
  }
19  
  new MouseMover mover;
20  
  mover.endAfterInterference = false;
21  
  mover.blockTimeAfterInterference = 1000;
22  
  mover.enable();
23  
  while licensed {
24  
    sleep(interval);
25  
    if (mover.blocked()) continue;
26  
    Point p = mouseLocation();
27  
    Rect area = new Rect(p.x-viewSize/2, p.y-viewSize/2, viewSize, viewSize);
28  
    BWImage img = shootScreenBW(area);
29  
    Pair<Float, Float> c = bwCentroid(img, useDarkCentroid);
30  
    ImageSurface is = quickShowZoomedImage(img.toRGB(), 4);
31  
    float cx = c.a-viewSize/2, cy = c.b-viewSize/2;
32  
    //Pt p2 = new Pt(iround(p.x+cx*speed), iround(p.y+cy*speed));
33  
    Pt p2 = new Pt(p.x+signWithThreshold(cx, minOffset), p.y+signWithThreshold(cy, minOffset));
34  
    print("Moving mouse " + (p2.x-p.x) + "/" + (p2.y-p.y) + " (centroid: " + formatDouble(cx, 2) + "/" + formatDouble(cy, 2) +")");
35  
    mover.moveMouseImmediate(p2);
36  
  }
37  
  mover.disable();
38  
}

Author comment

Began life as a copy of #1005820

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1005823
Snippet name: Continually move mouse to centroid; block for 1 second on interference
Eternal ID of this version: #1005823/1
Text MD5: 3fcb25c866100e123eedc6e4897ad173
Transpilation MD5: ff9159698f8a7e8312923f681e740593
Author: stefan
Category: javax / automation
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-10 17:30:07
Source code size: 1313 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 538 / 655
Referenced in: [show references]