Search This Blog

Tuesday, April 2, 2013

WiggleMouse.ahk

Everyone knows AutoHotKey. If you don't, it is a good time to find out about it.

I'd used AutoHotKey to come with with the small program below.
What it does is to wigggle the mouse after a certain delay, to sttart wiggle the mouse.
How is it useful? With displays becoming bigger, sometimes it is easy for the mouse to get lost. With the script running, you will be able to locate the mouse cursor more easily.
To top it off, you will be doing it with your peripheral vision, those vision rods receptors in your eyes that is so much better than detecting movments than the cones. So we are actually leveraging on our born ability to do ti.
You might need to replace the greater than and less than signs below if you are planning to use it.
Btw, running this application will have the side effect of preventing the screensaver from kicking in. So this is something you might want to consider.

WigglyMouse.ahk
#persistent
coordmode, mouse, screen
count := 0

mousegetpos, sx, sy

settimer, check, 250
return

check:
mousegetpos, cx, cy
  ; mouse has moved, calculate by how much
  count := count + 1
  ;ToolTip,  count is %count% 
  if ( count > 100 ){
    ;msgbox, mouse has moved less than 20 pixels
    if ( ((cx < (sx+20) and cx > (sx-20)) and (cy < (sy+20) and cy > (sy-20)))) {
      random, x, 1, 18
      random, y, 1, 18
      x := sx+x -9
      y := sy+y -9
      mousemove, %x%, %y%, 80
    }else {
      count := 0
      mousegetpos, sx, sy ; get new mouse position
    } 
  } 
return



updated.

for fun sake, I'd updated the script to draw lines on the screen. take a look.

#persistent
coordmode, mouse, screen
count := 0
unit := 40

OnExit, ExitSub
pToken := Gdip_Startup()
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hGui1 := WinExist()
hbm := CreateDIBSection(A_ScreenWidth, A_ScreenHeight), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4)
pPen := Gdip_CreatePen(0xff0000ff, 2)



mousegetpos, sx, sy

cx1 := sx 
cy1 := sy 

settimer, check, 200
return

check:
mousegetpos, zx, zy

if (( zx != sx and zx != cx ) or ( zy != sy and zy != cy )){
      count := 0
Gdip_GraphicsClear(G) ; not needed on first press, but never mind
UpdateLayeredWindow(hGui1, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight)

}
cx := zx
cy := zy
  ; mouse has moved, calculate by how much
  count := count + 1
  ;ToolTip,  count is %count% 
  if ( count > 50 ){
    ;msgbox, mouse has moved less than unit pixels
    if ( ((cx < (sx+unit) and cx > (sx-unit)) and (cy < (sy+unit) and cy > (sy-unit)))) {
      random, x, 1, (unit-2)
      random, y, 1, (unit-2)
      cx := sx+x -((unit -2)/2)
      cy := sy+y -((unit -2)/2)
      mousemove, %cx%, %cy%, 5

Gdip_DrawLine(G, pPen, cx, cy, cx1, cy1)
UpdateLayeredWindow(hGui1, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight)

      cx1 := cx
      cy1 := cy

    }else {
      count := 0
Gdip_GraphicsClear(G) ; not needed on first press, but never mind
UpdateLayeredWindow(hGui1, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight)
      mousegetpos, sx, sy ; get new mouse position
    } 
  } 
return


ExitSub:
Gdip_DeletePen(pPen)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc), Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
ExitApp

#Include Gdip.ahk    ; by Tic http://www.autohotkey.com/forum/topic32238.html