AutoHotkey Community

It is currently May 27th, 2012, 12:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Detect mouse movement
PostPosted: January 18th, 2006, 4:05 pm 
This one's been bugging me: (no pun intended)

I want to be able to detect when the mouse moves, so I can run an action, kind of like how screensavers exit on mouse movement.
-I didn't actually think it would be too hard but there are some unexpected problems.

I'm using the following script for debugging. The actions I want to run when the mouse moves, run even if I don't move the mouse.

Code:
Labelis:
Loop,
   {
   MouseGetPos, PosX1, PosY1
      Sleep, 500
      {
      MouseGetPos, PosX2, PosY2
      PosXA2 = %PosX2%
      PosXA2 += 50   ;prevents small mouse movements being detected
      PosXB2 = %PosX2%
      PosXB2 -= 50
      PosYA2 = %PosY2%
      PosYA2 += 50
      PosYB2 = %PosY2%
      PosYB2 -= 50
      if (PosX1 > PosXA)
         {
         Goto MouseMoved
         }
      else
      if (PosX1 < PosXB2)
         {
         Goto MouseMoved
         }
      else
      if (PosY1 > PosYA2)
         {
         Goto MouseMoved
         }
      else
      if (PosY1 < PosYB2)
         {
         Goto MouseMoved
         }
      }
   Sleep, 50
   }
return

MouseMoved:
MsgBox, Did you move the mouse? `n%PosX1% X1                %PosY1% Y1`n`n%PosXA2% large value X2    %PosYA2% large value Y2`n`n%PosXB2% small value X2    %PosYB2% small value Y2`n`nX1 or y1 should be outside these ranges ie. larger than a large value 2 or smaller than a small value 2.
Goto Labelis

#Persistent


Does the code need to be modified or enhanced? Or am I going about this completely the wrong way?
Thanks for your time.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 18th, 2006, 5:23 pm 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
This script produces a msgbox when the mouse is moved more than 50 pixels at one time, in any direction:

Code:
#persistent
coordmode, mouse, screen

mousegetpos, sx, sy

settimer, check, 250
return

check:
mousegetpos, cx, cy
if (cx != sx or cy != sy)
{
  ; mouse has moved, calculate by how much
  if (cx > (sx+50) or cx < (sx-50) or cy > (sy+50) or cy < (sy-50))
  {
    msgbox, mouse has moved more than 50 pixels
    mousegetpos, sx, sy ; get new mouse position
  } 
}     
return

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2011, 2:39 am 
I've been searching the forum and finally came accross this script by Serenity which I thought I am going to slightly modify to meet my needs i.e.
I need a single one (i.e. just 'one' as opposed to continuous non-stop clicking) left click everytime the mouse cursor moves a certain distance (e.g. >=50 pixels) and remains over that spot for some time (e.g. 1.5 sec).
I have an Evoluent Vertical Mouse 2 which has a similar functionality (see the image below), but it does continuous clicking on one spot, not a single click, which tends to screw up things for me, therefore I can't use this build-in functionality meanigfully.
So back to the script provided by Serenity - unfortunately it doesn't work for me i.e. no message is displayed regardless of the distance the mouse cursor travels i.e. > 50 pixels.
Any idea why it is not working and what needs to be modified in it, so it starts working, or some alternative solution, would be greatly appreciated.
Thank you in advance

Image


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2011, 3:07 am 
Offline

Joined: March 12th, 2011, 2:41 am
Posts: 3
Location: US
Please disregard my request - apparently, it was a false alarm.
My appologies, the script does work.
I had just placed the script code after the code in the script I already use, and this way by some reason the script couldn't function, but after I have moved the script code on top of my script, it started working properly.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2011, 3:25 am 
Offline

Joined: June 4th, 2010, 9:04 pm
Posts: 1347
Location: california
this is a possibility too

Code:
setmousepos:
mousegetpos, x1, y1
loop
{   gosub findmousenow
    sleep 1000
}
Exitapp

findmousenow:
mousegetpos, x2, y2
if ((%x1% <> %x2%) || (%y1% <> %y2%))
{  xmax := x1+50
   xmin := x1-50
   ymax := y1+50
   ymin := y1-50
   If x2 not between %xmax% And %xMin%
        goto gotmousemove
   if y2 not between %ymax% and %ymin%
        goto gotmousemove
return

gotmousemove:
; do whatever you need to do on a mouse move here
Return

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, chaosad, jrav, MSN [Bot] and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group