AutoHotKey使用教程

  • 格式:docx
  • 大小:54.71 KB
  • 文档页数:23

AutoHotKey使用教程/pikkaAutoHotKey使用教程(一)-----何为AutoHotKey?AutoHotKey是一个免费开源的小软件,很小(只有1964 KB),但是功能却非常强大,它几乎可以做键盘、鼠标和操纵杆可以做的任何事情。

它可以把人力完全的释放出来,前提只要你编写一个后缀为.ahk的脚本。

如果你愿意,你完全可以把你写的script理解为一个机器人,它可以做你想让它做的任何事情。

AutoHotKey在国外使用的很普遍,国内也有很大的用户群,大家只要Google 一下就知道了,AutoHotKey之前的版本是AutoIt2,现在newest的版本是AutoIt3,但是AutoHotKey还是一个比较经典的版本,最新的版本是1.0.47.04,建议大家下载一下,有什么使用心得,多交流哈,呵呵。

我会定期在我的博客上更新使用心得,大家多关注啊。

AutoHotKey使用教程(二)-----一个简单的例子使用AutoHotKey编写脚本非常简单,现在我们就来开始编写我们的第一个简单的脚本吧。

使用notepad或者其他你熟悉的文本编辑器,新建一个文件,使用.ahk作为后缀名,例如test.ahk 。

把下面的代码拷贝进去,保存退出,双击执行一下。

代码:MsgBox,你好,欢迎关注风追月博客 `n 请继续关注哈run, /pikka看到什么结果了吗?神奇吗?简单吗?呵呵如果感兴趣的话,我还会在后面的章节中,更加详细得讲解。

AutoHotKey使用教程(三)-----定义属于自己的热键通过本节的学习,你可以自定义热键快速启动常用的程序、文档、目录、网址和WINDOWS的常用功能(如:增大\减小音量、系统静音开关、弹出\关闭光驱、打开控制面板模块属性等等)。

在日常的工作中,它的确可以帮助您节省不少鼠标频繁点击的时间,从而大大的提高工作效率。

我们先来看一段简单的代码:#n::Run Notepadreturn在上面的代码中,"#"代表windows键(一种修饰符), "return"表示结束热键定义。

如果一个热键定义中只有一个语句,如上面的例子,那么这条语句就可以放在::的后面,不需要添加"return":#n:: Run Notepad如果热键包含多个按键,组合键连续的放在一起(不需要考虑顺序),下面的例子即使用^!来代替Control+Alt :^!s::Send Sincerely,{enter}John Smith ; This line sends keystrokes to the active (foremost) window.return你可以同时定义多个热键,它们触发相同的事件,只要把热键“垂直”定义即可。

^Numpad0::^Numpad1::MsgBox Pressing either Control+Numpad0 or Control+Numpad1 will display this message.return如果你要禁用某个热键,非常简单,只要在return之前不写任何语句即可,下面的例子就禁用的右边的Windows键RWin::returnAutoHotKey使用教程(四)----一些常用的修饰符AutoHotKey使用教程(五)----按键重映射按键重映射的语法格式:OriginKey::DestinationKey。

请看下面的例子:a::b在上面的例子中体会以下几点:1)使用键盘敲“a“,会自动映射成”b“2)敲”Shift + a “ 呢? B3)敲”capslock + a “ 呢? B4)敲”b“ 呢?还是ba::B1) 使用键盘敲“a“,会自动映射成”B“2) 敲”Shift + a “ 呢? B3) 敲”capslock + a “ 呢? b总结:”Shift + a “ 跟“a“的效果是一样的,”capslock + a “是按映射后在转换大小写。

鼠标的重映射语法跟按键重映射一致。

RAlt::RButton ; Makes the right Alt key behave like the right mouse button.RWin::Return ; Disables the right Windows key by having it simply return使用#IfWinActive/Exist语句可以控制重映射生效的窗口。

#IfWinActive ahk_class Notepada::b ; Makes the 'a' key send a 'b' key, but only in Notepad.#IfWinActive ; This puts subsequent remappings and hotkeys in effect for all windows.一段使用键盘控制鼠标的代码,大家有兴趣可以试一试。

*#up::MouseMove, 0, -10, 0, R ; Win+UpArrow hotkey => Move cursor upward *#Down::MouseMove, 0, 10, 0, R ; Win+DownArrow => Move cursor downward *#Left::MouseMove, -10, 0, 0, R ; Win+LeftArrow => Move cursor to the left*#Right::MouseMove, 10, 0, 0, R ; Win+RightArrow => Move cursor to the right*<#RCtrl:: ; LeftWin + RightControl => Left-click (hold downControl/Shift to Control-Click or Shift-Click).SendEvent {Blind}{LButton down}KeyWait RCtrl ; Prevents keyboard auto-repeat from repeating the mouse click.SendEvent {Blind}{LButton up}return*<#AppsKey:: ; LeftWin + AppsKey => Right-clickSendEvent {Blind}{RButton down}KeyWait AppsKey ; Prevents keyboard auto-repeat from repeating the mouse click.SendEvent {Blind}{RButton up}returnAutoHotKey使用教程(六)-----鼠标和键盘按键操作列表鼠标支持以下操作:LButton RButton MButton WheelDown WheelUp键盘按键支持以下操作:Space - the spacebarTabEnter (or Return)Escape (or Esc)Backspace (or BS)Delete (or Del)Insert (or Ins)HomeEndPgUpPgDnUpDownLeftRightScrollLockCapsLockNumLockNumlock ON Numlock OFFNumpad0 NumpadInsNumpad1 NumpadEndNumpad2 NumpadDownNumpad3 NumpadPgDnNumpad4 NumpadLeftNumpad5 NumpadClearNumpad6 NumpadRightNumpad7 NumpadHomeNumpad8 NumpadUpNumpad9 NumpadPgUpNumpadDot (.) NumpadDelNumpadDiv (/) NumpadDiv (/)NumpadMult (*) NumpadMult (*)NumpadAdd (+) NumpadAdd (+)NumpadSub (-) NumpadSub (-)NumpadEnter NumpadEnter1 a A LWinControl (orCtrl) Alt ShiftF1PrintScreen CtrlBreak PauseBreakAutoHotKey使用教程(七)-----AutoHotkey脚本AutoHotkey跟tcl等语言一样,是一种解释性语言。

从脚本的头部至结尾顺序执行,除非遇到return,exit或者热键、热字符串。

一个AutoHotkey脚本如果不包含热键、热字符串、OnMessage或者 GUI等,就会在文件执行完成后推出,否则脚本会处于idle状态以备相应热键、热字符串等操作。

`的用法类似于c和tcl中的“\”,例如`t (tab), `n (linefeed), and `r (carriage return).Autohotkey中逗号和百分号都有专门的意义,如果要表示字符意义,可以使用`, `%。

MsgBox This is ok.MsgBox, This is ok too (it has an explicit comma).AutoHotkey脚本使用“;”注释,“;”跟在需注释的语句之后,注意语句和分号之间只要要有一个空格。

如果要注意多个语句可以使用/* */Run Notepad ; This is a comment on the same line as a command./*MsgBox, This line is commented out (disabled).MsgBox, This one too.*/为了增加脚本的可读性和可维护性,有时需要将一个较长的语句拆分成几个较小的语句,可以使用以下几种方法:1)一行以"and", "or", ||, &&或者逗号开始,会自动跟上一句组合成一句。

FileAppend, This is the text to append.`n ; A comment is allowed here., %A_ProgramFiles%\SomeApplication\LogFile.txt ; Comment.if (Color = "Red" or Color = "Green" or Color = "Blue" ; Comment.or Color = "Black" or Color = "Gray" or Color = "White") ; Comment.and ProductIsAvailableInColor(Product, Color) ; Comment.2)这种方法适用于要连接很多行并且方法1不适用的情况。