MouseMove issue Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

MouseMove issue

24 Sep 2018, 04:27

I have a script that uses MouseMove and MouseClick in dependancy of a certain program being active. It all works absolute fine, but as soon as a second (not any apparently) script is active the mouse movement goes from almost instant to actually visible. Does anyone have ideas on what's causing it and how to get rid of it?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: MouseMove issue

24 Sep 2018, 05:33

without seeing the contents of the scripts who can really tell for sure?
it may be an issue with SendModes if ure using Input and hooked hotkeys in ur other script. See https://autohotkey.com/docs/commands/Se ... putUnavail
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

Re: MouseMove issue

24 Sep 2018, 06:14

Yeah, that is true. I thought that there maybe was a rather simple solution, because posting code and stuff is :effort:. :lol:

Code with issue (line 209-218)

Code: Select all

#SingleInstance, force
#NoEnv
;Avoids checking empty variables to see if they are environment variables
SendMode Input
;Switches to the SendInput method for Send, SendRaw, Click, and MouseMove/Click/Drag.
SetWorkingDir %A_ScriptDir%
;Script unconditionally uses its own folder as its working directory.
SetNumLockState, AlwaysOn
;Numlock set to always On


I_Icon = %A_ScriptDir%\Icons\W\lg.ico
Menu, Tray, Icon, %I_Icon%
Menu, Tray, Tip, Windows Helper V11ty.unicorn
return


#ScrollLock::Pause, Toggle
;Win+Pause pauses script
#Pause::Suspend, Toggle
;Win+Pause suspends hotkeys


~^s::
SetTitleMatchMode, 2
if WinActive(A_ScriptName)
	{
		SendInput, ^s
		SplashTextOn,,25, Status, Script updated
		Sleep,1000
		SplashTextOff
		Reload
		Sleep 1000
		MsgBox, 4,, The script was not reloaded, open it to edit?
		IfMsgBox, Yes, Edit
	}
else
	SendInput, ^s
return

;--------------------------------------------------------------------------------------

;Allgemein
;key substitutions
	numpaddot::.
			
	Capslock::Enter
	
;Hotkeys - !=Alt #=Win ^=Ctrl += Shift
	$F1::
		KeyWait, F1, T0.5
		if ErrorLevel
			;long
			SendInput, {F1}
		Else
			{
			KeyWait, F1, D T0.3
			if ErrorLevel
				;single
				SendInput, {F1}
			Else
				{
					;double
					If !WinExist("portal.REDACTED.de")
						{
							RunWait, http://portal.REDACTED.de/
						}
					WinMinimize, ahk_exe chrome.exe
					WinMinimize, ahk_exe sublime_text.exe
				}
			}
		return

	$F4::
		KeyWait, F4, T0.5
		if ErrorLevel
			;long
			SendInput, {F4}
		Else
			{
			KeyWait, F4, D T0.3
			if ErrorLevel
				;single
				SendInput, {F4}
			Else
				{
					;double
					WinGetActiveTitle, active_window
					WinMinimizeAll
					WinActivate, %active_window%
				}
			}
		return

	#^d::Run, https://extranet.REDACTED
	;Win+Ctrl+d

	#^w::Run, https://www.wikipedia.org/
	;Win+Ctrl+w

	#^Space::Run, https://www.google.com/
	;Win+Ctrl+Space

	#^e::Run, C:\Program Files\Microsoft Office 15\root\office15\EXCEL.EXE
	;Win+Ctrl+e

	#^n::Run, C:\Program Files\Microsoft Office 15\root\office15\OUTLOOK.EXE /c ipm.note,, Max
	;Win+Ctrl+n

	#!e::SendInput, REDACTED
	;Win+Alt+e

	#!k::SendInput, REDACTED
	;Win+Alt+k	

	<^>!p::SendInput, π
	;AltGr+p

	<^>!d::SendInput, Δ
	;AltGr+d


;Hotstrings
;Autocomplete
	:*:rep.::Rep.-Schalter
	:*:mfg::Mit freundlichen Grüßen, {Enter}{Enter}
	:*:xxxx::Sehr geehrte Frau{Space},{Left}
	:*:yyyy::Sehr geehrter Herr{Space},{Left}
	:*:xxyy::Sehr geehrte Damen und Herren,{Enter 2}
	:C*:vOv::¯\_(ツ)_/¯
	:*:dddd::
		FormatTime, CurrentDate,, yyyy-MM-dd
		SendInput, %CurrentDate%
	return
	:*:zzzz::
		FormatTime, CurrentDateTime,, yyyy-MM-dd-HH-mm
		SendInput, %CurrentDateTime%
	return
	:*:ssss::
		FormatTime, CurrentDate,, yyyy-MM-dd
		SendInput, %CurrentDate%_V4-3-1-10_jurca.ps5

;common spelling errors
	:*?:analge::anlage
	:*:Analge::Anlage
	:*:Kalrsruhe::Karlsruhe
	:*?:schlat::schalt
	:*:Schlat::Schalt
	
	;Misc.

;--------------------------------------------------------------------------------------

;REDACTED
#IfWinActive, ahk_exe REDACTED.ex_
		;Hotkeys
		^z::SendInput, {AltDown}br{AltUp}
		;Ctrl+z - undo

		^s::SendInput, {AltDown}ds{AltUp}
		;Ctrl+s - save

		#Tab::
		;Win+Tab - close text block
		SendInput, {Tab 9}
		SendInput, {Enter}
		return

		^!F2::
		;Alt+F2 - open datapoint and datapoint selection
		SendInput, {F2}
		Sleep, 50
		SendInput, {Tab 2}
		SendInput, {Space}
		return

		$F2::
		KeyWait, F2, T0.5
		if ErrorLevel 
			{
				;long
				CoordMode, Mouse, Client
				MouseGetPos, xpos, ypos
				MouseMove, 0, 0
				MouseClick, Left, 25, 50
				MouseClick, Left, 25, 260
				MouseClick, Left, 25, 50
				MouseMove, xpos, ypos
				return
			}
		Else
			{
				;single
				KeyWait, F2, D T0.2
				if ErrorLevel
					SendInput, {F2}
				Else
					{
						;double
						SendInput, {F2}
						Sleep, 50
						SendInput, {Tab 2}
						SendInput, {Space}
						return
					}
			}
    	return

		!F2::
		;Ctrl+Alt+F2 - deselect datapoint type
		CoordMode, Mouse, Client
		MouseGetPos, xpos, ypos
		MouseMove, 0, 0
		MouseClick, Left, 25, 50
		MouseClick, Left, 25, 260
		MouseClick, Left, 25, 50
		MouseMove, xpos, ypos
		return

		/* 
		;optional datapoint type deselection - can't be toggled
		^!F2::
		;Ctrl+Alt+F2 - deselect datapoint type
		SendInput, {Space}
		SendInput, {ShiftDown}{Tab 16}{ShiftUp}
		SendInput, {Space}
		SendInput, {Tab 15}
		SendInput, {Space}
		return
		
		;optional datapoint type deselection - needs adjustment of {Tab n} depending on number of active checkboxes
		^!F2::
		;Ctrl+Alt+F2 - deselect datapoint type (toggle)
		SendInput, {Space}
		SendInput, {Tab 18}
		SendInput, {Space}
		SendInput, {ShiftDown}{Tab 18}{ShiftUp}
		SendInput, {Space}
		return
		*/
		

		global break_g = 0
		~LButton::break_g = 1
		
		^+s::
		;Ctrl+Shift+s - single switch value of error message from 1 to 0 (highly dependant on correct Sleep interval; adjust if necessary)
		SendInput, {Enter}
		Sleep, 500
		SendInput, {AltDown}m{AltUp}
		Sleep, 500
		SendInput, {ShiftDown}{Tab 4}{ShiftUp}
		SendInput, {Space}
		Sleep, 500
		SendInput, {Enter}
		Sleep, 500
		SendInput, {Enter}
		return

		^+!s::
		;Ctrl+Shift+s - looped switch value of error message from 1 to 0 (highly dependant on correct Sleep interval; adjust if necessary)
		break_g = 0
		Loop, 5
		{
			SendInput, {Enter}
			Sleep, 500
			SendInput, {AltDown}m{AltUp}
			Sleep, 500
			SendInput, {ShiftDown}{Tab 4}{ShiftUp}
			SendInput, {Space}
			Sleep, 500
			SendInput, {Enter}
			Sleep, 500
			SendInput, {Enter}
			Sleep, 500
			SendInput, {Down}
			if(break_g = 1)
			{
				return
			}
		}
		return

		^Left::SendInput, {Left 10}
		;Ctrl+Left - move selection left 10 pixels 

		^Up::SendInput, {Up 10}
		;Ctrl+Up - move selection up 10 pixels 

		^Right::SendInput, {Right 10}
		;Ctrl+Right - move selection right 10 pixels 

		^Down::SendInput, {Down 10}
		;Ctrl+Down - move selection down 10 pixels 

		+Left::SendInput, {AltDown}bn{AltUp}
		;Shift+Left - rotate left

		+Right::SendInput, {AltDown}bc{AltUp}
		;Shift+Right - rotate right
#IfWinActive

;--------------------------------------------------------------------------------------

;REDACTED
#IfWinActive, ahk_exe REDACTED.exe
	;Hotkeys
		!k::
		;Alt+k
		;create comment
		MouseClick, Right
		SendInput, {Tab 2}
		SendInput, {Right}
		SendInput, {Up}
		SendInput, {Enter}
		MouseGetPos, xpos, ypos
		MouseMove, xpos + 10, ypos + 10
		
		;create border
		MouseClick, Right
		SendInput, {Tab 2}
		SendInput, {Right}
		SendInput, {Down 2}
		SendInput, {Tab}
		SendInput, {Enter}
		
		;create symbol
		MouseClick, Right
		SendInput, {Tab}
		SendInput, {Right}
		SendInput, {Down}
		SendInput, {Tab}
		SendInput, {Enter}
		return

		!^o::
		Gui,+AlwaysOnTop
		gui, add, button, x15 y5 h20 w120 gsub1, Haekchen setzen
		gui, add, button, x15 y30 h20 w120 gsub2, Haeckchen entfernen
		;gui, add, button, x40 y60 h20 w70 greload, Reload
		gui, add, button, x15 y85 h20 w120 gguiclose, Fenster schliessen
		;gui, add, button, x40 y110 h20 w70 gexit, Exit Script
		gui, show, x380 y100 w150 h150
		return
		
		sub1:
		{
			CoordMode, Pixel, Screen
			ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, %A_ScriptDir%\images\tickempty.png
			if ErrorLevel = 2
				MsgBox, Could not conduct the search.
			else if ErrorLevel = 1
				MsgBox, Icon could not be found on the screen.
			else
				CoordMode, Mouse, Screen
				MouseGetPos, posx, posy
				MouseClick, Left, Foundx + 5, FoundY +5
				MouseMove, posx, posy
			return
		}
		return
		
		sub2:
		{
			CoordMode, Pixel, Screen
			ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, %A_ScriptDir%\images\tick.png
			if ErrorLevel = 2
				MsgBox, Could not conduct the search.
			else if ErrorLevel = 1
				MsgBox, Icon could not be found on the screen.
			else
				CoordMode, Mouse, Screen
				MouseGetPos, posx, posy
				MouseClick, Left, Foundx + 5, FoundY +5
				MouseMove, posx, posy
			return
		}
		return
		
		;reload:
		;Reload
		
		guiclose:
		Gui, Destroy
		return
		
		;exit:
		; {
		;   exitapp
		; }
		;return
#IfWinActive

;--------------------------------------------------------------------------------------

;REDACTED
#IfWinActive, ahk_exe REDACTED.exe
;Hotkeys
	#Esc::
	;Win+Esc - save+close drawing
	SendInput, {Alt}
	SendInput, D
	SendInput, Z
	SendInput, {Enter 2}
	return
#IfWinActive
Code that leads to issue:

Code: Select all

;V1.0.1

#SingleInstance, force
SetWorkingDir %A_ScriptDir%

FileCreateShortcut, %A_ScriptFullPath%, %A_Startup%\%A_ScriptName%.lnk

I_Icon = %A_ScriptDir%\blue.ico
Menu, Tray, Icon, %I_Icon%
Menu, Tray, Tip, %A_ScriptName%
Menu, Tray, NoStandard
Menu, Tray, Add, Info..., guiAbout
Menu, Tray, Add, Hilfe, guiHelp
Menu, Tray, Add
Menu, Tray, Add, Sichern über REDACTED, guiSichern
Menu, Tray, Add, Wiederherstellen über REDACTED, guiHerstellen
Menu, Tray, Add, Ablage über Explorer, guiExplorer
Menu, Tray, Add
Menu, Tray, Add, Programm anhalten, gPause
Menu, Tray, Add, Beenden, gExit
return


#IfWinActive, REDACTEDProjektkonsole
~LButton::
	if WinExist("REDACTEDProjektkonsole","Sicherung")
		{
		MouseGetPos,,,, OutputVarControl
			if OutputVarControl = Button1
				Gosub, guiSichern
				OutputVarControl :=""
			return
		}
	else
		{
		if WinExist("REDACTED Projektkonsole","Wiederherstellung")
			MouseGetPos,,,, OutputVarControl
			if OutputVarControl = Button1
				Gosub, guiHerstellen
				OutputVarControl :=""
			return
		}
	return


;GUI REDACTED Sicherung
guiSichern:
	Gui, Destroy
	Gui, +E0x08000000 +AlwaysOnTop
	Gui, Show, x250 y250 w200 h200 NoActivate, %A_ScriptName%
	Gui, Add, Button, x40 y5 h50 w120 gSichern, Sichern
	Gui, Add, Button, x65 y160 h20 w70 gexit, Schließen
	return

Sichern:
	WinGet, win_id, ID, A
	ControlGetText bar_text, ToolbarWindow324, ahk_id %win_id%
	StringTrimLeft, currentPath, bar_text, 9
	FormatTime, CurrentDateTime,, yyyy-MM-dd_HH-mm
	FileDelete, %currentPath%\*abgelegt*.ps5
	FileAppend, , %currentPath%\%CurrentDateTime% die letzte Datensicherung wurde abgelegt durch %A_UserName%.ps5
		if ErrorLevel
			MsgBox,, Fehler, Achtung, es wurde keine Datei erzeugt!
		else
			{
			SplashTextOn,,25, Status, Datei wurde erzeugt.
			Sleep, 750
			SplashTextOff
			Gui, Destroy
			}
	currentPath :=""
	return


;GUI REDACTED Wiederherstellung
guiHerstellen:
	Gui, Destroy
	Gui, +E0x08000000 +AlwaysOnTop
	Gui, Show, x250 y250 w200 h200 NoActivate, %A_ScriptName%
	Gui, Add, Button, x40 y5 h50 w120 gHerstellen, Wiederherstellen
	Gui, Add, Button, x65 y160 h20 w70 gexit, Schließen
	return

Herstellen:
	WinGet, win_id, ID, A
	ControlGetText bar_text, ToolbarWindow323, ahk_id %win_id%
	StringTrimLeft, currentPath, bar_text, 9
	FormatTime, CurrentDateTime,, yyyy-MM-dd_HH-mm
	FileDelete, %currentPath%\*wiederhergestellt*.ps5
	FileAppend, , %currentPath%\%CurrentDateTime% Achtung! Das Projekt wurde wiederhergestellt von %A_UserName%.ps5
		if ErrorLevel
			MsgBox,, Fehler, Achtung, es wurde keine Datei erzeugt!
		else
			{
			SplashTextOn,,25, Status, Datei wurde erzeugt.
			Sleep, 750
			SplashTextOff
			Gui, Destroy
			}
	currentPath :=""
	return


;GUI Windows Explorer
guiExplorer:
	Gui, Destroy
	Gui, +E0x08000000 +AlwaysOnTop
	Gui, Show, x250 y250 w200 h200 NoActivate, %A_ScriptName%
	Gui, Add, Button, x40 y5 h20 w120 gExplorersub1, Sichern
	Gui, Add, Button, x40 h20 w120 gExplorersub2, Wiederherstellen
	Gui, Add, Button, x40 h20 w120 gExplorersub3, Ausbuchen
	Gui, Add, Button, x65 y170 h20 w70 gexit, Schließen
	return

Explorersub1:
	WinGet, win_id, ID, A
	ControlGetText bar_text, ToolbarWindow323, ahk_id %win_id%
	StringTrimLeft, currentPath, bar_text, 9
	FormatTime, CurrentDateTime,, yyyy-MM-dd_HH-mm
	FileDelete, %currentPath%\*abgelegt*.ps5
	FileAppend, , %currentPath%\%CurrentDateTime% die letzte Datensicherung wurde abgelegt durch %A_UserName%.ps5
		if ErrorLevel
			MsgBox,, Fehler, Achtung, es wurde keine Datei erzeugt!
		else
			{
			SplashTextOn,,25, Status, Datei wurde erzeugt.
			Sleep, 750
			SplashTextOff
			Gui, Destroy
			}
	currentPath :=""
	return

Explorersub2:
	WinGet, win_id, ID, A
	ControlGetText bar_text, ToolbarWindow323, ahk_id %win_id%
	StringTrimLeft, currentPath, bar_text, 9
	FormatTime, CurrentDateTime,, yyyy-MM-dd_HH-mm
	FileDelete, %currentPath%\*wiederhergestellt*.ps5
	FileAppend, , %currentPath%\%CurrentDateTime% Achtung! Das Projekt wurde wiederhergestellt von %A_UserName%.ps5
		if ErrorLevel
			MsgBox,, Fehler, Achtung, es wurde keine Datei erzeugt!
		else
			{
			SplashTextOn,,25, Status, Datei wurde erzeugt.
			Sleep, 750
			SplashTextOff
			Gui, Destroy
			}
	currentPath :=""
	return

Explorersub3:
	WinGet, win_id, ID, A
	ControlGetText bar_text, ToolbarWindow323, ahk_id %win_id%
	StringTrimLeft, currentPath, bar_text, 9
	FormatTime, CurrentDateTime,, yyyy-MM-dd_HH-mm
	InputBox, ausbuchen_name, REDACTED Ablage, Für wen wird die Sicherung ausgebucht?,,,150
		if ausbuchen_name =
			MsgBox,, Fehler!, Sie haben keinen Namen angegeben, bitte erneut versuchen.
		else
		{
			FileDelete, %currentPath%\*übergeben*.ps5
			FileAppend, , %currentPath%\%CurrentDateTime% Achtung! Das Projekt wurde übergeben an %ausbuchen_name%.ps5
				if ErrorLevel
					MsgBox,, Fehler!, Achtung, es wurde keine Datei erzeugt!
				else
					{
					SplashTextOn,,25, Status, Datei wurde erzeugt.
					Sleep, 750
					SplashTextOff
					Gui, Destroy
					}
			currentPath :=""
			ausbuchen_name :=""
		}
	return


gPause:
	menu, tray, ToggleCheck, Programm anhalten
	Suspend, Toggle
	Pause, Toggle
	return

gExit:
	ExitApp
	Return

guiAbout:
	Gui, 99:Destroy
	Gui, 99:Add, Text, ,REDACTED
	Gui, 99:Add, Text, ,Version V1.0.1, 2018-09-19
	Gui, 99:Add, Text, cblue ggitlink, GitHub
	Gui, 99:Add, Text,
	Gui, 99:Show, AutoSize
	return

gitlink:
	Run, https://github.com/REDACTED
	return

guiHelp:
	Run, https://github.com/REDACTED
	return

guiclose:
Gui, Destroy

exit:
Gui, Destroy
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: MouseMove issue  Topic is solved

24 Sep 2018, 08:18

its precisely as suspected. The context sensitive ~LButton:: from ur other script is implemented using the mouse hook, which causes the send mode in ur first script to revert to SendEvent. SendEvent has a default delay of 10ms. U can override it with SetMouseDelay to fix it:

Code: Select all

; first.ahk
#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Mouse

; SetMouseDelay -1, -1

q::
	MouseGetPos x, y
	MouseMove 0, 0
	MouseMove A_ScreenWidth, A_ScreenHeight
	MouseMove x, y
Return

Code: Select all

; second.ahk
;V1.0.1
#SingleInstance, force
SetWorkingDir %A_ScriptDir%

#IfWinActive, REDACTEDProjektkonsole
~LButton::MsgBox print something
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

Re: MouseMove issue

25 Sep 2018, 02:03

Awesome, it works - thank you!

Do I need both SetBatchLines and SetMouseDelay?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ArkuS, mikeyww and 321 guests