PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/docs/commands/_If.htm

http://autohotkey-chinese.googlecode.com/
HTML | 58 lines | 46 code | 12 blank | 0 comment | 0 complexity | eb6299f0b053dc5746e42aea8b2f6615 MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title>#If</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <link href="../css/default.css" rel="stylesheet" type="text/css">
  8. </head>
  9. <body>
  10. <h1>#If <span class="ver">[AHK_L]</span></h1>
  11. <p>创建上下文相关的 <a href="../Hotkeys.htm">热键</a> <a href="../Hotstrings.htm">热字串</a>. 这样的热键根据表达式的结果执行不同的操作 (或什么都不做).</p>
  12. <pre class="Syntax">#If [, Expression ]</pre>
  13. <h3>参数</h3>
  14. <table class="info">
  15. <tr>
  16. <td>Expression</td>
  17. <td>任何有效的 <a href="../Variables.htm#Expressions">表达式</a>.</td>
  18. </tr>
  19. </table>
  20. <h3>基本操作</h3>
  21. <p>可以使用任何有效的表达式定义激活活动的上下文. 例如:</p>
  22. <pre>#If WinActive("ahk_class Notepad") or WinActive(MyWindowTitle)
  23. #Space::MsgBox You pressed Win+Spacebar in Notepad or %MyWindowTitle%.</pre>
  24. <p> #IfWin 指令一样, #If 是可选的: 它影响脚本中所有实际在它后面的热键和热字串. #If #IfWin 同时也是互斥的; 即只有最近的 #If #IfWin 会起作用.</p>
  25. <p>要关闭上下文相关性, 请指定 #If 或任一 #IfWin 指令但省略所有参数. 例如:</p>
  26. <pre>#If</pre>
  27. <h3>一般说明</h3>
  28. <p>当按下了按键组合的其中一种形式的热键, #If 表达式的计算结果决定了是否应该激活热键. 只有在表达式计算完成或 <a href="_IfTimeout.htm">超时</a> 后系统才会响应键盘输入.</p>
  29. <p>由于 AutoHotkey 设计上的怪癖, #If 表达式在某些情况下可能被计算两次. 因此, #If 表达式应该设计为没有副作用.</p>
  30. <p><span class="ver">[AHK_L 53+]:</span> <a href="../Variables.htm#ThisHotkey">A_ThisHotkey</a> 包含了当前正在求值的 #If 表达式的热键名称</p>
  31. <h3>相关</h3>
  32. <p>大部分 <a href="_IfWinActive.htm">#IfWin</a> 指令的行为属性也适用于 #If.</p>
  33. <p><a href="_IfTimeout.htm">可以使用 </a>#IfTimeout 覆盖默认的超时时间值.</p>
  34. <h3 id="Examples">示例</h3>
  35. <pre class="NoIndent">
  36. <em>; 示例 1: Adjust volume by scrolling the mouse wheel over the taskbar.</em>
  37. #If MouseIsOver("ahk_class Shell_TrayWnd") WheelUp::Send {Volume_Up} WheelDown::Send {Volume_Down} MouseIsOver(WinTitle) { MouseGetPos,,, Win return WinExist(WinTitle . " ahk_id " . Win) }
  38. <em>; 示例 2: Simple word-delete shortcuts for all Edit controls.</em>
  39. #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) }
  40. <em>; 示例 3: Context-insensitive hotkey.</em>
  41. #If Esc::ExitApp
  42. <em id="ex4">; 示例 4: Dynamic hotkeys. <b>Requires Example 1.</b></em>
  43. NumpadAdd:: Hotkey, If, MouseIsOver("ahk_class Shell_TrayWnd") if (doubleup := !doubleup) Hotkey, WheelUp, DoubleUp else Hotkey, WheelUp, WheelUp return DoubleUp: Send {Volume_Up 2} return
  44. </pre>
  45. </body>
  46. </html>