Jump to content


If mouse is NOT moving then sends key. Otherwise do nothing


  • Please log in to reply
2 replies to this topic

#1 kram

kram
  • Guests

Posted 21 May 2012 - 09:49 AM

hello,

I need your help.
My goal is to create a script which will work in this concrete way:

When (using web browser Firefox) I will press left mouse button and hold it still for 0,5 sec. without any mouse moving, then it will send Ctrl+Shift+Click to open link in new tab in background
But when I will press left mouse button and hold it BUT with moving mouse, then do default thing e.g. selecting text

This scirpt below sends desire command when I press and hold left button for 0,5 sec., but I would like to make it work only when the cursor remains motionless for hakf a secong.
I don't want to put in this sricpt any "BlockInput, MouseMove" commands cause this is not my point and after pressing mouse button I want to keep the possibility of moving mouse for e.g. selecting text
I only want from script to detects id mouse is in motion (changes itself possition during that 0,5 sec or NOT) and if NOT only when sends my specified command.
Now, when I press left button and hold it for selectnig text (when of course during selecting mouse is in motion), then it stops selecting after 0,5 sec and sends ctrl+shift+click.
And I don't wnat this behaviour :)

So, please someone helps me
I'll be truly thankful

#IfWinActive ahk_class MozillaWindowClass
~LRButton::
MouseGetPos, xpos, ypos
KeyWait, LButton, T0.5
          if   ErrorLevel
                    Send ^+{Click, 1}
          else
Return
#IfWinActive


#2 Pulover

Pulover
  • Members
  • 1253 posts

Posted 21 May 2012 - 11:57 AM

You only need to do another MouseGetPos after ErrorLevel and compare with the last one.
Like this:
~LButton::
MouseGetPos, xpos, ypos
KeyWait, LButton, T0.5
	if   ErrorLevel
	{
		MouseGetPos, xposn, yposn
		If (xpos = xposn) AND (ypos = yposn)
			Send ^+{Click, 1}
	}
	else
Return


#3 kram

kram
  • Guests

Posted 21 May 2012 - 12:18 PM

Thanks a lot, Pulover! :D
This is exactly what I was looking for.