AHKv2.0 Ahk2Exe Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
egocarib
Posts: 100
Joined: 21 May 2015, 18:21

Re: AHKv2.0 Ahk2Exe

21 Oct 2016, 16:24

Well, the first problem seems to be that SetTitleMatchMode doesn't work as documented for AHKv2 (http://lexikos.github.io/v2/docs/comman ... chMode.htm)

The default option is supposed to be 2 ("A window's title can contain WinTitle anywhere inside it to be a match")

Even when I set it explicitly to 2, it still doesn't match a partial window title.

Here's example code you can test. Try to use both hotkeys in an untitled notepad window. Only the first one with the exact window title works.

Code: Select all

SetTitleMatchMode(2)
Hotkey("IfWinActive", "Untitled - Notepad ahk_class Notepad")
Hotkey("^a", "TEST1", "On")
Hotkey("IfWinActive", "Untitled ahk_class Notepad")
Hotkey("^b", "TEST2", "On")
return

TEST1:
TEST2:
Msgbox(A_ThisLabel)
return
egocarib
Posts: 100
Joined: 21 May 2015, 18:21

Re: AHKv2.0 Ahk2Exe

23 Oct 2016, 12:09

Thanks, HotKeyIt! Things seem to be working well now.
egocarib
Posts: 100
Joined: 21 May 2015, 18:21

Re: AHKv2.0 Ahk2Exe

24 Oct 2016, 13:51

Okay, new fun issue of the day. :)

My script relies on blocking clicks and keyboard input for a certain window. If the window is active, all keyboard input is blocked. If the window isn't active, clicks are monitored globally and clicks on that window are not allowed by the script.

This works well in my uncompiled script. It also works well when compiled.... until a MsgBox appears. There seems to be something different in how the MsgBox is handled after the script is compiled. It ends up locking up the script because once the MsgBox is open, the compiled script prevents ALL clicks (and the CONSUME_WINDOW_CLICKS label is not even launched on click anymore - it stops working)

Here's a test script you can use to reproduce the issue. Open an Untitled - Notepad window, run the script, and press the hotkey. You'll be able to click around the screen just fine and you can type in any window except for the notepad window. However, when the MsgBox appears, the mouse locks up entirely - you can't click the MsgBox or any other window at that point.

Try it uncompiled and it works fine, though. The MsgBox doesn't lock anything up.

Any idea what the issue is?

Code: Select all


^a::

	notepadID := WinGetID("Untitled - Notepad ahk_exe NOTEPAD.EXE")
	BlockWindowInput(true, notepadID)
	Sleep(10000)
	Msgbox("Try clicking anywhere now...`n`n(If this is compiled, you can't. Press ENTER to close the MsgBox.)")
	BlockWindowInput(false, notepadID)

Return



BlockWindowInput(cmd, winID) ;special function to block R/L clicking over a specific window (whether active or not) and also block keypresses when the window is active
{
	global g_winID

	If (cmd)
	{
		g_winID := winID
		BlockUserKeys(true, "ahk_id %winID%") ;block keypresses (only when window is active)
		Hotkey("IfWinActive") ;global click override
		Hotkey("*vk01", "CONSUME_WINDOW_CLICKS", "On") ;left click
		Hotkey("*vk02", "CONSUME_WINDOW_CLICKS", "On") ;right click
	}
	Else
	{
		BlockUserKeys(false, "ahk_id %winID%") ;unblock keypresses for window
		Hotkey("IfWinActive")
		Hotkey("*vk01", "CONSUME_WINDOW_CLICKS", "Off") ;left click
		Hotkey("*vk02", "CONSUME_WINDOW_CLICKS", "Off") ;right click
		g_WinID := ""
	}
	Return

	CONSUME_WINDOW_CLICKS:
		hk := A_ThisHotkey
		MouseGetPos(_mx, _my, _mwin)
		if _mwin != g_WinID
		{
			TrayTip("Test", "You clicked somewhere else!", 10)
			;if mouse isn't over a forbidden window, send virtual click event
			Send("{" . SubStr(hk, 2) . "}")
		}
		else
		{
			TrayTip("Test", "You clicked on Untitled - Notepad!", 10)
			;simulate click by activating window without sending the click event to it
			WinActivate("ahk_id %_mwin%")
		}
	RETURN
}


;block keyboard input while a specific window is active
BlockUserKeys(cmd, activeWindowTitle := "")
{
	If (activeWindowTitle)
	{
		Hotkey("IfWinActive", activeWindowTitle) ;turn on window sensitivity
	}
	If (cmd)
	{
		Loop 511 ;Block keystrokes
			Hotkey("*sc" . Format("{1:#x}", A_Index), "CONSUME_INPUT", "On")
	}
	Else
	{
		Loop 511 ;Unblock keystrokes
			Hotkey("*sc" . Format("{1:#x}", A_Index), "CONSUME_INPUT", "Off")
	}
	If (activeWindowTitle)
	{
		Hotkey("IfWinActive") ;turn off hotkey window sensitivity
	}

	CONSUME_INPUT:
	RETURN
}
egocarib
Posts: 100
Joined: 21 May 2015, 18:21

Re: AHKv2.0 Ahk2Exe  Topic is solved

25 Oct 2016, 18:59

Today I noticed that there is now an AHK v2 .bin file included in the standard v2 download file (https://autohotkey.com/download/ahk-v2.zip).

Using that .bin file, I compiled the script with fincs' Ahk2Exe and it is now working as expected.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Albireo, coder96, CraigM, Draken, Frogrammer, w_i_k_i_d and 61 guests