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

65
LINES

< > BotCompany Repo | #1015142 // Mouse ToolTip & Log & Key Log [OK]

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

Download Jar. Uses 4281K of libraries. Click here for Pure Java version (14025L/98K).

!7

static double interval = 1.0;
static new LatestAppearance<S> latest;
sS tooltip;
static RectAndMD5 mouse;
static Rect rectShown;
static int maxClipWidth = min(600, screenWidth()/2);
static int maxClipHeight = min(300, screenHeight()/2);

p-subst {
  autoRestart();
  startBotHere("Screen Segmenter.", #1015121);

  onGlobalKeyPress(voidfunc(NativeKeyEvent e) {
    mechAppend_noUniq_inQ("Key log",
      "User pressed key " + e.getKeyCode() + " with modifiers " + e.getModifiers());
  });
  
  onGlobalMousePress(voidfunc(NativeMouseEvent e) {
    lock defaultLock();
    int x = e.getX(), y = e.getY();
    makeToolTip(Pt(x, y));
    S text;
    if (mouse == null)
      text = "User clicked at " + x + "/" + y + " (" + screenWidth() + "x" + screenHeight() + ")";
    else
      text = "User clicked on " + (empty(tooltip) ? "uncommented object of size " + mouse.r.w + "x" + mouse.r.h : multiLineQuote(tooltip)) + " at " + x + "/" + y + " (screen: " + screenWidth() + "x" + screenHeight() + ", rect: " + mouse.r + ", md5: " + mouse.md5 + ")";
    mechAppend_noUniq_inQ("Mouse log", text);
  });
  
  S tooltip = ""; // mouse
  repeat with sleep interval {
    time2 {
      L<S> list = latest.recordAndSort(thingsOnScreen2());
      
      makeToolTip(mousePt());
    }
    print(localDateWithSeconds() + ": Found: " + list);
    consoleTitle(l(list) + " " + joinWithComma(list));
  }
}

svoid makeToolTip(Pt mousePt) {
  lock defaultLock();
  L<RectAndMD5> rects = segmentedScreenFromCacheFile_last;
  mouse = firstRectAndMD5Containing(rects, mousePt);
  S name = "";
  
  if (mouse != null)
    name = unnull(thingsOnScreenDefinitions().get(mouse.md5));
  if (neq(name, tooltip)) flatInfoBox_topRightCorner(tooltip = name, 1.0);
  
  Rect r = mouse == null ? null : mouse.r;
  if (r != null && empty(name) && neq(r, rectShown)
   && r.w <= maxClipWidth && r.h <= maxClipHeight) {
    double zoom = 1;
    int x = max(r.w, r.h);
    if (x < 30) zoom = 3.0;
    else if (x < 100) zoom = 2.0;
    ImageSurface is = zoomedImageSurface(shootScreenArea_possiblyBroken(mouse.r), zoom);
    showWindowInTopRightCorner(is, 3.0);
  }
  rectShown = r;
}

Author comment

Began life as a copy of #1015126

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1015142
Snippet name: Mouse ToolTip & Log & Key Log [OK]
Eternal ID of this version: #1015142/1
Text MD5: 089d4a74383855489d138096031957d3
Transpilation MD5: 201f0ba333602e7664f9a9724483c41a
Author: stefan
Category: javax / ocr
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-08 21:12:47
Source code size: 2213 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 468 / 1069
Referenced in: [show references]