AutoHotkey

Find all sorts of guides created by our community here. Includes guides such as drug use, roleplaying different types of characters, weapons etc.

Moderators: Game Admins, LS-RP Testers, Player Support Mods, Lead Admins

Forum rules
The guides you see here have been unofficially created by the players, for the players. LSRP cannot be held responsible for the accuracy of any of the content you see here.
Post Reply
User avatar
Hemingway
Mafia
Mafia
Posts: 494
Joined: Sun May 08, 2011 5:34 pm

AutoHotkey

Post by Hemingway » Mon Jun 20, 2016 2:14 am

AutoHotkey


SPACER1. Introduction

I've recently found out about AutoHotkey and I got pretty interested. I decided to make a guide (tutorial) on how it can be useful and how you can implement it into SA-MP. I was inspired to make this guide by Chas. I felt the need to remaster his old guide and expand it.

I will try to make things as simple and as clean as possible. If you have any critics on my work or any advices that you would like to share, feel free to contact me.



SPACER2. Quick Beginner Explanation

AutoHotkey (AHK) is a free, open-source macro-creation and automation software for Windows that allows users to automate repetitive tasks. That includes things such as:
  • remap keys and buttons on your keyboard, joystick, and mouse;
  • create keybinds for keyboard, joystick, and mouse (any key, button or combination can become a keybind);
  • expand abbreviations as you type them.
    For example, typing "btw" can automatically produce "by the way".

In this guide, you are not going to be learning the whole AutoHotkey language but rather copy-pasting and understanding the functions you really need in-game.



SPACER3. Why AutoHotkey?


ADVANTAGES
fast
no bloatware
more options
DISADVANTAGES
requires a bit more time & understanding to tune the keybinds






I've recently switched to AutoHotkey after 6 years of using regular keybind programs and I'm very satisifed. It gives you much more control of over what you want to do and how you want to do it. Best thing about it is that it's pretty simple to learn, all you need is a few minutes and some motivation. You'll be glad you learned it BUT you can also just copy and paste premade functions from this guide.



SPACER4. Installation

This part is pretty easy. Visit https://autohotkey.com/ and download the latest version of the software. After you download it, install it with Express settings and you're ready to go.



SPACER5. Setting Up

Thing about making keybinds with AutoHotkey is that we don't have an actual graphical user interface for it.

To start making our keybinds we're going to be making a new file. Do that by right-clicking on your desktop, expanding "New" and then clicking "AutoHotkey Script".


Image


This is going to create a new file on your desktop. After it's created, we're going to right-click on it and select "Edit Script".


Image


By default, Notepad should now pop up and you should be able to edit the file.

Erase everything in that file and start fresh.

Image



SPACER6. Basic Keybinds

To make a keybind in AutoHotkey, you need to know which key are you going to be using and what is it going to do.

You can find full list of keys and mouse buttons for AutoHotkey right here.

For example, we want to make a bind that's going to write: "/me smiles." and we want Numpad 1 to be the key we're going to use. This is how we write it.


Image

Code: Select all

Numpad1:: Sendinput t/me smiles.{ENTER}


If we want to maybe talk after we have smiled we can also write & use this.


Image

Code: Select all

Numpad1:: Sendinput t/me smiles.{ENTER}tYou're funny.{ENTER}


You can also use this if you want to do another emote after the first one. You just need to edit the second part as if it was the first.

If we want maybe to use a combination of keys as a keybind we can also do that. Most common example of that is control (CTRL). We just need to add the ^ before our main key (Numpad 1).


Image

Code: Select all

^Numpad1:: Sendinput t/me smiles.{ENTER}


You also don't have to use {ENTER} for your keybinds. Maybe you have a keybind which for the most part is always the same, but it needs a small change at the end. For example, we want to say: "Thank you, <someone's name>." but we don't want to type "Thank you" every time.


Image

Code: Select all

Numpad1:: Sendinput tThank you, 



SPACER7. Advanced Keybinds

AutoHotkey offers a lot more options to use. We're going to go through a few more.



SPACER7.1. Using sleep function

Thing you can also use in your keybinds is actually a "timer". You can set the time between two emotes or two sentences. You do that by implementing the sleep function. Time is measured in milliseconds which means that 1 second is equal to 1000 milliseconds.

Code: Select all

Numpad1:: 
Sendinput t/me smiles.{ENTER}
sleep, 2000
Sendinput t/me runs away.{ENTER}
return



SPACER7.2. Using if statement

This second one is a bit more complicated for those who don't have experience in programming but it's still pretty easy.

Basically, we have two operations on one bind. We want Numpad 1 to roll down our window and we want it to roll it back up IF it's already rolled down. And this is basically all this function does. It checks if the windows is rolled down or is it up and based on that it writes an appropriate emote. If "window" has a value of 0 — it means it is rolled up. If "window" has a value of 1 — it means it is rolled down.

Code: Select all

Numpad1:: 
if (window = 1) {
   Sendinput t/ame rolls the window back up.{ENTER}
   window = 0
} else {
   Sendinput t/ame rolls the window down.{ENTER}
   window = 1
}
return



SPACER7.3. Use keybinds only for SAMP

This one is pretty simple. We obviously don't want our keybinds to run in programs such as Chrome. That's why we can add #IfWinActive to our script.

Code: Select all

#IfWinActive GTA:SA:MP
   ^e:: SendInput t/enter{enter}
   ^r:: SendInput t/exit{enter}
   ^k:: SendInput t/lock{enter}
   ^j:: SendInput t/engine{enter}



SPACER7.4. Expanding abbreviations

This can be used very often. For example, we want AutoHotkey to write "by the way" when we type in "btw". We can do that very easy.

Code: Select all

:?:btw::by the way
return


I have seen a lot of police officers using this as their bind to take guns out and place them back in cruiser's gun rack. We're going to use some code from earlier and implement it here. Basically, when we write "shotty" and when we press enter it's going to make an emote and it's going to execute a command that's appropriate.

Code: Select all

:?:shotty::
   if (shotgun = 1) {
      Sendinput t/me places a shotgun back into the gun rack.{ENTER}t/place 25{ENTER}
      shotgun = 0
   } else {
      Sendinput t/me takes a shotgun from the gun rack.{ENTER}t/takegun 25{ENTER}
      shotgun = 1
   }
return
Last edited by Hemingway on Sat Mar 04, 2017 6:15 pm, edited 2 times in total.

User avatar
Varsatorul
Wannabe Don
Wannabe Don
Posts: 1529
Joined: Wed Dec 28, 2011 4:37 pm
Location: Romania
Contact:

Re: AutoHotkey

Post by Varsatorul » Tue Jun 21, 2016 5:00 pm

Great guide! Although the window bind is obsolete due to the new /rollwindow command, it still serves as a good example for more advanced things that can be achieved by using Autohotkey instead of other keybinders.

You could even make a script for shifting gears through /ame or /me that remembers what gear you're on or for turn signaling if you'd want to. Or if you'd like to do the /reload anim and a /me one after the other and you don't have time to type them out you could bind both actions to the same hotkey.

Or for the advertisers out there you could make a bind that cycles through advertisements and does an /ad every 60 seconds with the use of one button. Pretty neat, huh? please don't do that
WWW.VARSATORUL.NET
MODDING SHOWROOM

User avatar
Hemingway
Mafia
Mafia
Posts: 494
Joined: Sun May 08, 2011 5:34 pm

Re: AutoHotkey

Post by Hemingway » Thu Jun 23, 2016 12:15 am

Thank you very much, mate. There are plenty of things you can do. I'm just laying out the parts and basics that you need to know to make various combinations of keybinds. I believe you can keybind almost everything that you have just suggested with what I have written in the first post.

I've just updated the topic with 7.4. and will continue to update as I learn more about AutoHotkey. I'd like to make use of chatlog.txt but we'll see.

User avatar
Marsijuana
Wannabe Mafia
Wannabe Mafia
Posts: 152
Joined: Thu Aug 22, 2013 4:41 pm
Location: Indonesia

Re: AutoHotkey

Post by Marsijuana » Sat Mar 04, 2017 1:19 pm

I want to ask something, I don't know how to explain my question but I hope you understand, for example:
the function of Numpad 1 is : t/me unholster their sidearm.
So the question is... are there any AHK commands to holster the sidearm back with the same keys? So if I pressed Numpad1 again after t/me unholster their sidearm, It will be t/me holster their sidearm.
soz for my bad english.
Image
"The moment people come to know love, they must bear the risk of hatred."

User avatar
Hemingway
Mafia
Mafia
Posts: 494
Joined: Sun May 08, 2011 5:34 pm

Re: AutoHotkey

Post by Hemingway » Sat Mar 04, 2017 6:14 pm

It's explained right there in the post, try not to be lazy next time. :wink:

Code: Select all

Numpad1::
   if (sidearm = 1) {
      Sendinput t/me holsters his sidearm.{ENTER}
      sidearm = 0
   } else {
      Sendinput t/me unholsters his sidearm.{ENTER}
      sidearm = 1
   }
return

User avatar
Marsijuana
Wannabe Mafia
Wannabe Mafia
Posts: 152
Joined: Thu Aug 22, 2013 4:41 pm
Location: Indonesia

Re: AutoHotkey

Post by Marsijuana » Sun Mar 05, 2017 1:34 am

Ohh sorry my bad, thanks btw!
Image
"The moment people come to know love, they must bear the risk of hatred."

Post Reply

Return to “Player-Created Guides”

Who is online

Users browsing this forum: No registered users and 5 guests