home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 August / maximum-cd-2010-08.iso / DiscContents / AutoHotkey104805_Install.exe / AutoHotkey.chm / docs / scripts / contextsensitivehelp.ahk next >
Encoding:
Text File  |  2009-09-25  |  2.4 KB  |  74 lines

  1. ; Context Sensitive Help in Any Editor -- by Rajat
  2. ; http://www.autohotkey.com
  3. ; This script makes Ctrl+2 (or another hotkey of your choice) show the help file
  4. ; page for the selected AutoHotkey command or keyword. If nothing is selected,
  5. ; the command name will be extracted from the beginning of the current line.
  6.  
  7. ; The hotkey below uses the clipboard to provide compatibility with the maximum
  8. ; number of editors (since ControlGet doesn't work with most advanced editors).
  9. ; It restores the original clipboard contents afterward, but as plain text,
  10. ; which seems better than nothing.
  11.  
  12. $^2::
  13. ; The following values are in effect only for the duration of this hotkey thread.
  14. ; Therefore, there is no need to change them back to their original values
  15. ; because that is done automatically when the thread ends:
  16. SetWinDelay 10
  17. SetKeyDelay 0
  18. AutoTrim, On
  19.  
  20. if A_OSType = WIN32_WINDOWS  ; Windows 9x
  21.     Sleep, 500  ; Give time for the user to release the key.
  22.  
  23. C_ClipboardPrev = %clipboard%
  24. clipboard =
  25. ; Use the highlighted word if there is one (since sometimes the user might
  26. ; intentionally highlight something that isn't a command):
  27. Send, ^c
  28. ClipWait, 0.1
  29. if ErrorLevel <> 0
  30. {
  31.     ; Get the entire line because editors treat cursor navigation keys differently:
  32.     Send, {home}+{end}^c
  33.     ClipWait, 0.2
  34.     if ErrorLevel <> 0  ; Rare, so no error is reported.
  35.     {
  36.         clipboard = %C_ClipboardPrev%
  37.         return
  38.     }
  39. }
  40. C_Cmd = %clipboard%  ; This will trim leading and trailing tabs & spaces.
  41. clipboard = %C_ClipboardPrev%  ; Restore the original clipboard for the user.
  42. Loop, parse, C_Cmd, %A_Space%`,  ; The first space or comma is the end of the command.
  43. {
  44.     C_Cmd = %A_LoopField%
  45.     break ; i.e. we only need one interation.
  46. }
  47. IfWinNotExist, AutoHotkey Help
  48. {
  49.     ; Determine AutoHotkey's location:
  50.     RegRead, ahk_dir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
  51.     if ErrorLevel  ; Not found, so look for it in some other common locations.
  52.     {
  53.         if A_AhkPath
  54.             SplitPath, A_AhkPath,, ahk_dir
  55.         else IfExist ..\..\AutoHotkey.chm
  56.             ahk_dir = ..\..
  57.         else IfExist %A_ProgramFiles%\AutoHotkey\AutoHotkey.chm
  58.             ahk_dir = %A_ProgramFiles%\AutoHotkey
  59.         else
  60.         {
  61.             MsgBox Could not find the AutoHotkey folder.
  62.             return
  63.         }
  64.     }
  65.     Run %ahk_dir%\AutoHotkey.chm
  66.     WinWait AutoHotkey Help
  67. }
  68. ; The above has set the "last found" window which we use below:
  69. WinActivate
  70. WinWaitActive
  71. StringReplace, C_Cmd, C_Cmd, #, {#}
  72. send, !n{home}+{end}%C_Cmd%{enter}
  73. return
  74.