自动热键:在激活某些窗口时切换大写锁定 [英] Autohotkey: Toggle caps lock on/off on activating certain windows
问题描述
我想编写一个脚本,当我激活一个在其标题中包含特定关键字的窗口(例如SQL)时,该脚本将启用大写锁定.我还希望在切换到其标题不包含我指定的任何关键字的窗口时关闭大写锁定.
I want to write a script that will turn on caps lock when I activate a window containing particular keyword in its title(like SQL). I also want the caps lock to be turned off when I switch to a window whose title does not contain any of the keywords that I have specified.
我该怎么办?我考虑过#Persistent
与一个计时器,以定期检查活动窗口.但是,我认为应该有更好的方法.
How can I do it? I have considered #Persistent
with a timer to periodically check active window. But, I think there should be a better way.
推荐答案
check answers at: http://www.reddit.com/r/AutoHotkey/comments/1qjf83/force_specific_program_to_use_caps/. Especially G33kDude's answer. It's a clever and efficient solution: check of current window is binded only to windows activation.
======================
=======================
在下面插入代码. 请注意,这不是一个完整的解决方案,您需要根据需要进行一些编辑.不过不算大.
Code inserted below. Please note that it's not a complete solution, you'll need to make some edits for your needs. Not a big ones, though.
#Persistent ; Don't close when the auto-execute ends
SetTitleMatchMode, 2 ; Partial title matching
WinGet, myHwnd, ID, Notepad ; Get the handle to the your window
; Listen for activation messages to all windows
DllCall("CoInitialize", "uint", 0)
if (!hWinEventHook := DllCall("SetWinEventHook", "uint", 0x3, "uint", 0x3, "uint", 0, "uint", RegisterCallback("HookProc"), "uint", 0, "uint", 0, "uint", 0))
{
MsgBox, Error creating shell hook
Exitapp
}
;MsgBox, Hook made
;DllCall("UnhookWinEvent", "uint", hWinEventHook) ; Remove the message listening hook
return
; Handle the messages we hooked on to
HookProc(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime)
{
global myHwnd
static lastHwnd
WinGetTitle, title, ahk_id %hwnd%
if (hwnd == myHwnd) ; If our window was just activated
{
tooltip, Gained focus
}
else if (lastHwnd == myHwnd) ; If our window was just deactivated
{
tooltip, Lost focus
}
lastHwnd := hwnd
}
这篇关于自动热键:在激活某些窗口时切换大写锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!