[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
    评论
### 回答1: 你可以使用AutoHotkey编写一个脚本来实现在Windows 10上使用热键来隐藏/显示桌面图标。以下是一个简单的示例脚本: #NoEnv SendMode Input SetWorkingDir %A_ScriptDir% ; 隐藏桌面图标 ^!h:: DllCall("Shell32.dll\SHGetSetSettings", "ptr", , "ptr", x00000001, "ptr", , "uint", ) WinGetClass, ProgmanClass, Progman WinGetClass, WorkerWClass, WorkerW WinHide, ahk_class %ProgmanClass% WinHide, ahk_class %WorkerWClass% return ; 显示桌面图标 ^!s:: DllCall("Shell32.dll\SHGetSetSettings", "ptr", , "ptr", x00000002, "ptr", , "uint", ) WinGetClass, ProgmanClass, Progman WinGetClass, WorkerWClass, WorkerW WinShow, ahk_class %ProgmanClass% WinShow, ahk_class %WorkerWClass% return 在这个脚本中,我们使用了两个热键:Ctrl+Alt+H来隐藏桌面图标,Ctrl+Alt+S来显示桌面图标。当按下Ctrl+Alt+H时,脚本会调用Shell32.dll中的SHGetSetSettings函数来隐藏桌面图标,然后使用WinHide命令隐藏Progman和WorkerW窗口。当按下Ctrl+Alt+S时,脚本会调用SHGetSetSettings函数来显示桌面图标,然后使用WinShow命令显示Progman和WorkerW窗口。 请注意,这个脚本可能不适用于所有的Windows 10系统,因为不同的系统可能使用不同的窗口类名来表示桌面图标。如果你发现这个脚本不能正常工作,请尝试使用其他的窗口类名。 ### 回答2: 在Windows 10操作系统中,我们可以通过自定义热键来实现隐藏/显示桌面图标的功能。为此,我们需要先下载并安装AutoHotkey这一免费软件,然后新建一个AHK文件(后缀名为.ahk),在其中输入以下代码: #NoTrayIcon #Persistent #IfWinActive ahk_class Progman ^!d:: SendMessage 0x111, 0x7, 0, 0, , Progman Return 其中,“#NoTrayIcon”表示喊AutoHotkey将不会在系统托盘中显示图标,“#Persistent”则表示脚本将持续运行,“#IfWinActive ahk_class Progman”指定当桌面为当前活动窗口时才会生效。 然后,在代码中的“^!d::”后面,我们可以自定义所需的热键,这里的“^”表示Ctrl键,“!”表示Alt键,“d”表示D键,即组合键Ctrl+Alt+D。我们可以根据实际需求修改热键。发送消息“SendMessage 0x111, 0x7, 0, 0, , Progman”则实现了隐藏/显示桌面图标的功能。 当我们保存并运行该脚本后,在Windows 10操作系统中使用Ctrl+Alt+D组合键,即可实现隐藏/显示桌面图标的功能。需要注意的是,该脚本的效果不会立即生效,我们需要重新启动Windows Explorer程序或注销/重新登录才能看到效果。 总的来说,通过AutoHotkey软件自定义热键可以方便快捷地实现Windows 10系统中的各种功能,包括隐藏/显示桌面图标。但是需要注意的是,在操作时请确保准确按下组合键,以避免出现意外情况。 ### 回答3: 在Windows 10操作系统中,隐藏和显示桌面图标的方法有很多种,其中使用热键是一种方便快捷的方式。 首先,我们需要使用AutoHotkey(AHK)软件来定义一个热键。AutoHotkey是一款小巧而强大的脚本语言软件,它可以让我们自定义各种热键和脚本,实现更为高效的电脑操作。如果没有安装AutoHotkey,我们需要先下载和安装此软件。 接着,我们打开AutoHotkey软件,右键点击桌面,选择“新建AutoHotkey脚本”,在打开的编辑器中书写以下代码: ^!h:: WinGet, exStyle, Style, ahk_class Progman If (exStyle & 0x100) { WinSet, Style, -0x100, ahk_class Progman WinGet, ExStyle, Style, ahk_class WorkerW WinSet, Style, -0x20, ahk_class WorkerW } Else { WinSet, Style, +0x100, ahk_class Progman WinGet, ExStyle, Style, ahk_class WorkerW WinSet, Style, +0x20, ahk_class WorkerW } 上述代码的含义是:按下Ctrl+Alt+H的热键,可以隐藏或显示桌面图标。当桌面图标处于显示状态时,按下此热键会隐藏桌面图标;反之,当桌面图标处于隐藏状态时,按下此热键会显示桌面图标。 最后,我们保存脚本,并双击打开它。接着,我们就可以使用Ctrl+Alt+H的热键快捷地隐藏或显示桌面图标了。当然,如果需要修改热键,可以在脚本中将“^!h”更改为其他热键。 总之,使用热键可以让我们更方便快捷地隐藏和显示桌面图标,极大地提高了我们的工作效率和操作体验。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值