[AHK]只在某些特定情景生效的热键

105 篇文章 5 订阅
;在某特定控件激活时生效。可以在记事本中测试(编辑窗口为Edit1控件),在Word中不生效:

#If ActiveControlIs("Edit1")
6::Send {F5}
7::MsgBox
#If

ActiveControlIs(Control) {
    ControlGetFocus, FocusedControl, A
    return (FocusedControl=Control)
}



在某类控件激活时生效,代码如下

; 示例 : 在所有的编辑控件中的轻松删除单词的快捷键.
#If ActiveControlIsOfClass("Edit")
^BS::Send ^+{Left}{Del}
^Del::Send ^+{Right}{Del}

ActiveControlIsOfClass(Class) {
    ControlGetFocus, FocusedControl, A
    ControlGet, FocusedControlHwnd, Hwnd,, %FocusedControl%, A
    WinGetClass, FocusedControlClass, ahk_id %FocusedControlHwnd%
    return (FocusedControlClass=Class)
}

#If


无需激活在某类窗口上即生效。代码如下

; 示例 : 在任务栏上滚动鼠标来调节音量.
#If MouseIsOver("ahk_class Shell_TrayWnd")
WheelUp::Send {Volume_Up}
WheelDown::Send {Volume_Down}

MouseIsOver(WinTitle) {
    MouseGetPos,,, Win
    return WinExist(WinTitle . " ahk_id " . Win)
}


在某特定窗口激活时生效,用#IfWin 指令可以简单地创建窗口激活时的、上下文相关的热键. 例如:

#IfWinActive ahk_class Notepad
#space::MsgBox You pressed Win+Spacebar in Notepad.
#IfWinExist ahk_class Notepad
#n::WinActivate  ; 激活由 #IfWin 找到的窗口.

在某些窗口激活时生效,通过 #IfWinActive ahk_group MyGroup 使用窗口组



函数化:

#IfWinActive, - Microsoft Outlook ahk_class RCtrl_renwnd32 ;for Outlook 2010, uncomment this line
y::HandleOutlookKeys("^+1", "y") ;archive message using Quick Steps Hotkey (ctrl+Shift+1)
f::HandleOutlookKeys("^f", "f") ;forwards message
r::HandleOutlookKeys("^r", "r") ;replies to message
#IfWinActive

HandleOutlookKeys( specialKey, NormalKey )
{
    ;Activates key only on main outlook window, not m, tasks, contacts, etc.
    IfWinActive, - Microsoft Outlook ahk_class RCtrl_renwnd32, NUIDocumentWindow, ,	;for Outlook 2010, uncomment this line
    {
      ;Find out which control in Outlook has focus
      ControlGetFocus currentCtrl, A
      ;Set list of controls that should respond to specialKey. Controls are the list of emails and the main
      ;(and minor) controls of the reading pane, including controls when viewing certain attachments.
      ctrlList = Acrobat Preview Window1,AfxWndW5,AfxWndW6,EXCEL71,MsoCommandBar1,OlkPicturePreviewer1,paneClassDC1,OutlookGrid1,OutlookGrid2,RichEdit20WPT2,RichEdit20WPT4,RichEdit20WPT5,RICHEDIT50W1,SUPERGRID2,SUPERGRID1,_WwG1
      If currentCtrl in %ctrlList%
          Send %specialKey%
      ;Allow typing normalKey somewhere else in the main Outlook window. (Like the search field or the folder pane.)
      Else
          Send %NormalKey%
    }
  ;Allow typing normalKey in another window type within Outlook, like a mail message, task, appointment, etc.
  Else
    {
      Send %NormalKey%
    }
  }



  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值