/en/_posts/2011-11-03-Your-First-Script.markdown

https://github.com/brigand/ahkbook · Markdown · 51 lines · 36 code · 15 blank · 0 comment · 0 complexity · 52e0c20c147df88ff7cf83a3b501ee94 MD5 · raw file

  1. ---
  2. title: Your first script
  3. layout: post
  4. permalink: /en/Your-First-Script.html
  5. ---
  6. # Your first script
  7. ## Let's start
  8. Now you should have chosen your AutoHotkey version, your editor, and you should have set up both.
  9. We'll do our first script now.
  10. ## Create a script file
  11. If you have used the AutoHotkey classic or AutoHotkey\_L installer, right-click on your desktop or any folder and select New > AutoHotkey Script from the context menu. Open the newly created file in your editor. If you haven't run an installer, just open your editor and save it as a file with the extension ".ahk".
  12. In the editor, type the following code:
  13. {% highlight ahk %}
  14. MsgBox Hello, World!
  15. {% endhighlight %}
  16. Save your file now.
  17. ---
  18. ### Note:
  19. Make sure you chose the correct encoding. If you have installed AutoHotkey classic or AutoHotkey\_L ANSI, use, of course, ANSI, otherwise use UTF-8.
  20. * In Windows Notepad, this setting is available under `File` > `Save As...` > `encoding`.
  21. * In Notepad++, it's in the menu bar under `Encoding`.
  22. ---
  23. ## Execute your script
  24. If you have run an installer, just double-click the file for executing it. Otherwise use the command line to run `[Path/To/YourAutoHotkey].exe "[Path/to/your/script].ahk"`.
  25. For IronAHK, run `mono IronAHK.exe [Path/to/our/script].ahk`.
  26. You should see a box appear similar to the screenshot below:
  27. ![MsgBox screenshot]({{ site.url }}/Images/Hello-World-1.en.png)
  28. ## What happened?
  29. The first word in your code above, `MsgBox`, is an AutoHotkey command that instructs AutoHotkey to show that box. The rest of the code is, as you might have guessed, the message to display.
  30. ## Extending that example
  31. You can customize the MsgBox further:
  32. ![2nd MsgBox screenshot]({{ site.url }}/Images/Hello-World-2.en.png)
  33. Use the following code:
  34. {% highlight ahk %}
  35. MsgBox, 36, a question, Would you like to say 'Hello, World'?
  36. {% endhighlight %}