Mouse movement to action script bug

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Mouse movement to action script bug

Post by hemsith14_ » 05 Jan 2023, 20:49

The following script it not working properly when the hotkey ^!mbutton is being used. Any other hotkey that doesn't include ctrl or alt works fine. Any idea how to fix this without changing it to a different hotkey?

Code: Select all

^!mbutton::
		current := 0
		MouseGetPos,, y1
		while (GetKeyState("MButton", "P"))
		{
			MouseGetPos,, y2
			offset := (y2-y1)//10 ; set scroll per pixel
			if (current != offset)
			{
				count := offset-current
				loop % Abs(count)
				Send % count > 0 ? "!{WheelUp}" : "!{WheelDown}"
				current := Offset
			}
			Sleep 10
		}
		return
Last edited by hemsith14_ on 05 Jan 2023, 23:37, edited 1 time in total.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Mouse movement to action script bug

Post by hemsith14_ » 05 Jan 2023, 22:57

? :angel: :angel: ?

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse movement to action script bug

Post by mikeyww » 06 Jan 2023, 06:57

Try SendInput.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Mouse movement to action script bug

Post by hemsith14_ » 06 Jan 2023, 11:19

The mode is already input.

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse movement to action script bug

Post by mikeyww » 06 Jan 2023, 11:24

I do not see that. Which line?

A different script may yield different results, so post the broken script rather than something different.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Mouse movement to action script bug

Post by hemsith14_ » 06 Jan 2023, 11:25

Code: Select all

SendMode Input

^!mbutton::
		current := 0
		MouseGetPos,, y1
		while (GetKeyState("MButton", "P"))
		{
			MouseGetPos,, y2
			offset := (y2-y1)//10 ; set scroll per pixel
			if (current != offset)
			{
				count := offset-current
				loop % Abs(count)
				Send % count > 0 ? "!{WheelUp}" : "!{WheelDown}"
				current := Offset
			}
			Sleep 10
		}
		return
P.S you can try it too and see that it produces weird results with Sendmode input and event

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse movement to action script bug

Post by mikeyww » 06 Jan 2023, 11:54

It worked here. Perhaps others will reproduce your difficulty.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Mouse movement to action script bug

Post by hemsith14_ » 06 Jan 2023, 12:00

Using the hotkey as ^!MButton worked fine for you?

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse movement to action script bug

Post by mikeyww » 06 Jan 2023, 12:02

Yes, though it flashes the program's menu bar, because Alt has a way of doing that!

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Mouse movement to action script bug

Post by hemsith14_ » 06 Jan 2023, 12:20

Full script here, it just doesn't work as expected. It starts fine but then you have to release and re-press the hotkey in order for it to work again. I have no idea why. It works fine with MButton alone.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^!mbutton::
		Current := 0
		MouseGetPos,, Y1
		While (GetKeyState("MButton", "P"))
		{
			MouseGetPos,, Y2
			Offset := (Y2-Y1)//13
			If (Current != Offset)
			{
				Count := Offset-Current
				Loop % Abs(Count)
				Send % Count > 0 ? "!{WheelUp}" : "!{WheelDown}"
				Current := Offset
			}
		}
		Return
		
		
^2::
reload
return

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse movement to action script bug

Post by mikeyww » 06 Jan 2023, 12:29

At any point in this thread, have you provided a detailed description of what the script is supposed to do?

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Mouse movement to action script bug

Post by hemsith14_ » 06 Jan 2023, 13:28

It should turn Ctrl + Alt + MButton + Mouse movement to !wheelup and down.

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse movement to action script bug

Post by mikeyww » 06 Jan 2023, 13:30

It did work here in Notepad. As I noted, it does flash the menu bar, presumably due to the sending or pressing of Alt.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Mouse movement to action script bug

Post by hemsith14_ » 06 Jan 2023, 13:44

If I leave MButton, keep Alt + Ctrl down and re-press MButton, the hotkey wont execute again. Any idea why?

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse movement to action script bug

Post by mikeyww » 06 Jan 2023, 14:46

I suspect that your Send inside the loop forces AutoHotkey to release some keys, so your hotkey will then not immediately trigger again because those modifiers are now up. Examining the key history will be a way to understand & confirm that. You can also prove it by removing that Send line and seeing that the repetition is now possible.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Mouse movement to action script bug

Post by hemsith14_ » 06 Jan 2023, 15:09

So how can I fix that?

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse movement to action script bug

Post by mikeyww » 06 Jan 2023, 16:11

The first step to resolution is understanding. As I already mentioned, understanding is gained by examining your key history to understand what is happening to the modifier keys before, during, and after your Send command. The resolution will then be crafted based on the understanding.

A demonstration is below.

Code: Select all

#Requires AutoHotkey v1.1.33
#InstallKeybdHook
#If GetKeyState("Ctrl", "P") & GetKeyState("Alt", "P")
*MButton::
While GetKeyState("MButton", "P") {
 SendInput !{WheelUp}
 Sleep 20
}
Return
#If

Post Reply

Return to “Ask for Help (v1)”