Hotkeys Not Working Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

Hotkeys Not Working

16 Jan 2020, 15:05

I'm trying to write a script that will minimize the active window when I press the right Windows key alone, and close the active window when I press the right Windows key while the right control key is held down.

This is what I have so far.

Code: Select all

#NoEnv
SetBatchLines -1

DllCall("QueryPerformanceFrequency", "Int64*", freq)
GroupCreate("ExplorerUI", "ahk_class Shell_TrayWnd", "ahk_class WorkerW", "ahk_class DV2ControlHost", "ahk_class NotifyIconOverflowWindow")
Loop {
	KeyWait RWin, D
	DllCall("QueryPerformanceCounter", "Int64*", RWinP)
	KeyWait RWin
} return

#If qpc() - RWinP << 1 <= freq and A_PriorKey == "RWin" and WinActive(,, "ahk_group ExplorerUI")

RWin Up:: PostMessage 0x112, 0xF020		; Minimize the active window
>^RWin Up:: GetKeyState("RCtrl", "P") and WinClose()	; Close the active window

#If

GroupCreate(GroupName, Rules*) {
	For Index, Rule in Rules
		GroupAdd % GroupName, % Rule
}

qpc() {
	DllCall("QueryPerformanceCounter", "Int64*", p)
	return p
}

WinClose(WinTitle := "", WinText := "", ExcludeTitle := "", ExcludeText := "") {
	PostMessage 0x112, 0xF060,,, % WinTitle, % WinText, % ExcludeTitle, % ExcludeText
	return ErrorLevel
}
I'm trying to use WinExist() in the #If condition to target the window rather than specifying it in the command to avoid the target window changing to an improper target during the execution of the command. However, the hotkeys in the above script don't seem to be working—that is, they work with all windows, rather than excluding those specified in the ExcludeTitle parameter. If I replace the call to WinActive(,, "ahk_group ExplorerUI") with a call to WinExist("A",, "ahk_group ExplorerUI") or WinActive("A",, "ahk_group ExplorerUI"), then the hotkeys do nothing. Can someone help?
theholyscripture
Posts: 62
Joined: 26 Apr 2019, 17:11

Re: Hotkeys Not Working

16 Jan 2020, 21:19

1100++ wrote:
16 Jan 2020, 15:05
I'm trying to write a script that will minimize the active window when I press the right Windows key alone, and close the active window when I press the right Windows key while the right control key is held down.

This is what I have so far.

Code: Select all

#NoEnv
SetBatchLines -1

DllCall("QueryPerformanceFrequency", "Int64*", freq)
GroupCreate("ExplorerUI", "ahk_class Shell_TrayWnd", "ahk_class WorkerW", "ahk_class DV2ControlHost", "ahk_class NotifyIconOverflowWindow")
Loop {
	KeyWait RWin, D
	DllCall("QueryPerformanceCounter", "Int64*", RWinP)
	KeyWait RWin
} return

#If qpc() - RWinP << 1 <= freq and A_PriorKey == "RWin" and WinActive(,, "ahk_group ExplorerUI")

RWin Up:: PostMessage 0x112, 0xF020		; Minimize the active window
>^RWin Up:: GetKeyState("RCtrl", "P") and WinClose()	; Close the active window

#If

GroupCreate(GroupName, Rules*) {
	For Index, Rule in Rules
		GroupAdd % GroupName, % Rule
}

qpc() {
	DllCall("QueryPerformanceCounter", "Int64*", p)
	return p
}

WinClose(WinTitle := "", WinText := "", ExcludeTitle := "", ExcludeText := "") {
	PostMessage 0x112, 0xF060,,, % WinTitle, % WinText, % ExcludeTitle, % ExcludeText
	return ErrorLevel
}
I'm trying to use WinExist() in the #If condition to target the window rather than specifying it in the command to avoid the target window changing to an improper target during the execution of the command. However, the hotkeys in the above script don't seem to be working—that is, they work with all windows, rather than excluding those specified in the ExcludeTitle parameter. If I replace the call to WinActive(,, "ahk_group ExplorerUI") with a call to WinExist("A",, "ahk_group ExplorerUI") or WinActive("A",, "ahk_group ExplorerUI"), then the hotkeys do nothing. Can someone help?
A lot of that code seems a bit beyond what I can understand.

This code might help, but I'm guessing it's probably not quite what you're looking for.

Code: Select all

RWin::
WinMinimize, A ; A corresponds to Active Window - see https://www.autohotkey.com/docs/misc/WinTitle.htm for more
Return

RWin & RCtrl::
WinClose, A
Return
Helgef
Posts: 4467
Joined: 17 Jul 2016, 01:02
Contact:

Re: Hotkeys Not Working

17 Jan 2020, 10:15

Hi, as I pointed out :arrow: here, the exclude parameter is not a WinTitle paramter, it is just for excluding strings in the windows titles, meaning that, winactive(,,"ahk_group mygroup") will match any window whose title doesn't contain (depending on settitlematchmode) the literal text ahk_group mygroup.

Cheers.

Edit, @1100++, glad it worked out for you :thumbup:.
Last edited by Helgef on 18 Jan 2020, 00:02, edited 1 time in total.
1100++
Posts: 78
Joined: 10 Feb 2018, 19:05

Re: Hotkeys Not Working  Topic is solved

17 Jan 2020, 15:19

Helgef, the post you linked to inspired a workaround.

Code: Select all

#NoEnv
SetBatchLines -1

DllCall("QueryPerformanceFrequency", "Int64*", freq)
Loop {
	KeyWait RWin, D
	DllCall("QueryPerformanceCounter", "Int64*", RWinP)
	KeyWait RWin
} return

#If qpc() - RWinP << 1 <= freq and A_PriorKey == "RWin" and WinExist("A")
	and !in(WinGetClass(), "Shell_TrayWnd,NotifyIconOverflowWindow,DV2ControlHost,WorkerW")

RWin Up:: PostMessage 0x112, 0xF020		; Minimize the active window
>^RWin Up:: GetKeyState("RCtrl", "P") and WinClose()	; Close the active window

#If

in(String, MatchList) {
	If String in %MatchList%
		return true
	return false
}

WinGetClass(WinTitle := "", WinText := "", ExcludeTitle := "", ExcludeText := "") {
	WinGetClass ClassVar, % WinTitle, % WinText, % ExcludeTitle, % ExcludeText
	return ClassVar
}

qpc() {
	DllCall("QueryPerformanceCounter", "Int64*", p)
	return p
}

WinClose(WinTitle := "", WinText := "", ExcludeTitle := "", ExcludeText := "") {
	PostMessage 0x112, 0xF060,,, % WinTitle, % WinText, % ExcludeTitle, % ExcludeText
	return ErrorLevel
}

Return to “Ask For Help”

Who is online

Users browsing this forum: anv, artur1884, Bing [Bot], Google [Bot], hasantr, submeg and 44 guests