[GUIDE] Autohotkey easy for everyone

Find all sorts of guides created by our community here. Includes guides such as drug use, roleplaying different types of characters, weapons etc.
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.
User avatar
Airwalk
Game Administrator
Posts: 7160
Joined: Wed May 30, 2012 5:52 am

[GUIDE] Autohotkey easy for everyone

Post by Airwalk » Wed Dec 16, 2015 7:20 am

This is an easy tutorial for beginners to understand the basic functions of Autohotkey, useful for the usage on LSRP.

I am reminding you of the rules regarding binds. You are not allowed to use binds to ease your roleplay or gain advantages, I will not take responsibility for anyone abusing Autohotkey for the aforementioned.

If you still don't get around with Autohotkey, you can also check the third post of the thread or comment here to get guidance/assistance from me.

Regards,

Airwalk.
Last edited by Airwalk on Wed Dec 16, 2015 7:31 am, edited 2 times in total.
NOT ENOUGH

User avatar
Airwalk
Game Administrator
Posts: 7160
Joined: Wed May 30, 2012 5:52 am

Re: [GUIDE] Autohotkey easy for everyone

Post by Airwalk » Wed Dec 16, 2015 7:21 am

1. Download Autohotkey and creation of your first script
1.1 Installing autohotkey
Before getting anything to work, we need a compiler with all the functions. The compiler can be found on the official autohotkey website, then you download Autohotkey_L.
After the download is finished, you go through the custom installation!
When being asked for the version, you pick Autohotkey_L 32Bit ANSI, it has the best compatibility, then you hit Install script compiler and install it.

1.2 Installing an editor with Syntax-Highlighting (optional, but recommended!)
I recommend downloading a an editor right at the beginning, because it displays the code in different colors, thus it is recommended because the code is easier to read.
You simply download the programm called SciTE4AutoHotkey, download and install it, but also don't forget to tick Set as default .ahk file editor.
It runs itself after the installation, then you can do all the settings you wish (language preferences etc.)

1.3 How to create a script
Creating a script is simple. You just create a folder or however you prefer to organise your files, then right click in the folder and then "Autohotkey script" along with the basic things like "New folder" appears.

2. Creation of hotkeys
2.1 A simple keybind
Now we're moving on to the creation of a simple keybind, upon triggering a set hotkey. We will start with /lock being sent upon pressing "1". Therefore, we use one of the many functions of Autohotkey, called SendInput alternatively you could also use Send or SendRaw, though I recommend the usage of SendInput, because the other two are slower and not useful for longer texts in your hotkeys.
Explanation: show
We start with chosing the hotkey you wish to use to trigger your bind, in this example I will be using the 1 key on every keyboard. A hotkey is a "registered key", meaning a key, that is occupied with a function. The key stays occupied, until the script is closed or we do this manually (see further below).
You "register" a key, by adding a :: to your hotkey, an example would be KEY:: or 1:: for our example with using the key 1.
As explained above, I recommend the usage of SendInput to give the key a function, so it would look like this with the example of /lock:

1::
SendInput t/lock

The "t" automatically opens the chatlog for you, to type in the command. Now you want to close the chatbox as well, that is simply done by adding a {enter} beside your keybind, to simulate pressing the enter key:

1::
SendInput t/lock{enter}

To round everything up, add a return beneath your keybind, to prevent errors in your script.

How does the proper keybind look like now?

Code: Select all

1::
SendInput t/lock{enter}
return

2.2 Modify hotkey prefix symbols
Now, a brief description of prefix symbols; like control, alt, shift etc. A full list can be found here.
Example: show
# Stands for Win (Windows-Logo-Key)
! Stands for Alt
^ Stands for Ctrl
+ Stands for Shift

Hotkey example:
!1::
The key 1 was triggered in combination with Alt.

With the keybind created in 2.1, the example would be:

Code: Select all

!1::
SendInput t/lock{enter}
return


2.3 Sleep function
The word sleep is self-explaining, but in the means of Autohotkey, it means the script is paused for a set amount of time.
The usage is simple, if you wish to have multiple binds with one hotkey and also add a delay, you use the sleep function by adding a Sleep, TIMEINMS (Sleep, 1000 would mean that the script is paused for 1 second, alternatively 1000 milliseconds).
Explanation: show
Starting with the /lock command again, saying that you want to automatically lock your vehicle after unlocking and entering it.
You write the bind regulary,
1::
Sendinput t/lock{enter}

But now we also add the sleep function to the script, to achieve what was said above,

Code: Select all

1::
SendInput t/lock{enter}
Sleep 5000
SendInput t/lock{enter}
return
Now, the script unlocks your car and grants you five seconds to enter it, before it automatically locks again. Of course you can alter the time in milliseconds and use it for everything you possibly imagine.


2.4 Send texts with Autohotkey
Now that you learned how to trigger your hotkeys, we will move on to sending longer texts.
Usage: SendInput TEXT
Attention! As mentioned above, we have learned how to use hotkey prefix symbols (windows key, ctrl, alt etc), those cannot be sent just like that, they have to be put in between a { and }. This also includes keys with a name that has more than 1 character eg. ENTER, TAB, or ESCAPE.
Example: show
Sending a text without any specialties:

Code: Select all

1::
SendInput tHello world, how are you?{enter}
return
This sends a regular chat message into the IC chat.

Hotkeys with prefix symbols:

Code: Select all

2::
SendInput tHELP{!}{!}{!}{enter}
return
The exclamation mark has to be put into the { } as well, because it'll give you an error when you compile your script and won't let it work.

Typing into the chatbox, to make an addition to your hotkey:

Code: Select all

3::
SendInput t/ticket  68127592 Being dumb{HOME}{right 8}
return
This could be used for tickets, if you don't know the amounts, as an example. The hotkey sends the text of the ticket, the amount. The {HOME} automatically moves your cursor to the far left side of your chatbox and the {right 8} moves your cursor 8 figures to the side, where you type the ID of the player you wish to ticket. This can be, ofcourse used for many other things as well.


2.5 Hotstrings ("/test")
Hotstrings are the concatenation of single hotkeys, as the titles says: ("/test").
The structure is similiar to the regular hotkeys, but you need to add two colons (:) infront and beside the hotkey.
Explanation: show
("::hi::") -> when typing "hi" in the regular chatbox, you say "Hello" in the IC chat.

Code: Select all

::hi::
SendInput Hello.{enter}
return
We do not place a t infront of the bind, because the chatbox is already opened.

Another example for a / bind would be:

Code: Select all

:?:/dumb::
SendInput /fine 123 $69 being stupid{enter}
return
The question mark (?) in between the colon (:) is used to make the bind work in SAMP only, not in your browser, skype, teamspeak or whatever.


2.6 Creation of a loop
Loops can be permanent or one-timed.
Usage: Loop, AMOUNT (if you leave the AMOUNT out, it creates a permanent loop).
A loop is used permanently, unless you add a return or break.
Examples: show
Example 1:
Use a loop five times

Code: Select all

1::
Loop, 5
{
    SendInput t/fish{enter}
}
/fish will be sent 5 times.

Example 2:
Use a loop indefinitely

Code: Select all

1::
Loop
{
    SendInput t/fish{enter}
}
/fish will be sent indefinitely.

Example 3:
Use a loop until a certain key is pressed

Code: Select all

1::
Loop,
{
SendInput t/fish{enter}
Keywait,<,D,T2
If !errorlevel
{
SendInput t/myfish{enter}
return
}
}
Return
The loop will be sent every 2 seconds (T2) until you press < (or any other key you replace it with in the script). Upon pressing <, the loop will stop and send /myfish as a last command, to end the loop and show the results of it.
NOT ENOUGH

User avatar
Airwalk
Game Administrator
Posts: 7160
Joined: Wed May 30, 2012 5:52 am

Re: [GUIDE] Autohotkey easy for everyone

Post by Airwalk » Wed Dec 16, 2015 7:30 am

I'm also offering script creation and script repair support in this thread.

If you have problems with your script, you can post the snippets here. If they are big, you can send me a PM.

If you need a script created, you can also post here or send me a PM, simply include which bind you want on which key. I'm quite experienced with it, so I can do somewhat complicated things too.
NOT ENOUGH

User avatar
drgraphics
Wannabe Don
Wannabe Don
Posts: 964
Joined: Wed Jul 09, 2014 9:44 pm

Re: [GUIDE] Autohotkey easy for everyone

Post by drgraphics » Wed Dec 23, 2015 3:32 pm

Nice guide bro. :) I may send you a PM sometime. :wink:

LSFD Command | Captain #001 - Louis Emerson
Captain of Administrative Divisions
Public Relations Division - Commander
Recruitment Division Command - Senior Recruitment Officer
Training Division Command - Chief Instructor
Department Hospital Services - Attending Physician
Mental Health Bureau - Psychologist

Image
https://i.imgur.com/G9LklCk.gif

User avatar
Slaughter_
Bronze Member
Bronze Member
Posts: 65
Joined: Wed Apr 22, 2015 2:49 pm
Ingame name: Remi Coxx
Contact:

Re: [GUIDE] Autohotkey easy for everyone

Post by Slaughter_ » Wed Dec 23, 2015 3:57 pm

Nice going, very helpful.

User avatar
UnfairestBow
Gangster
Gangster
Posts: 61
Joined: Fri Jan 17, 2014 9:35 pm
Ingame name: Ryan_Wheeler
Location: Sweden.

Re: [GUIDE] Autohotkey easy for everyone

Post by UnfairestBow » Sat Dec 26, 2015 8:57 pm

Sweet, helped me a lot. Thanks!

User avatar
Airwalk
Game Administrator
Posts: 7160
Joined: Wed May 30, 2012 5:52 am

Re: [GUIDE] Autohotkey easy for everyone

Post by Airwalk » Sun Dec 27, 2015 8:30 pm

Thanks. If you want more functions explained and added, you can tell me which and I see what I can do.
NOT ENOUGH

carulet
Gangster
Gangster
Posts: 134
Joined: Tue Oct 27, 2015 1:29 pm

Re: [GUIDE] Autohotkey easy for everyone

Post by carulet » Sat Jan 16, 2016 12:58 pm

I keep on crashing when I use a ShowDialog bind with UDF. Any help?!?!

User avatar
TheWordAwesomeIsAwesome
Gangster
Gangster
Posts: 104
Joined: Sat Jan 09, 2016 2:04 am
Ingame name: Alexander_Richardson
Location: Italy

Re: [GUIDE] Autohotkey easy for everyone

Post by TheWordAwesomeIsAwesome » Sat Jan 16, 2016 6:45 pm

If just I had read this guide before now I would be rich with the Fishing Job. :lol:
Nice work.
Image

User avatar
Airwalk
Game Administrator
Posts: 7160
Joined: Wed May 30, 2012 5:52 am

Re: [GUIDE] Autohotkey easy for everyone

Post by Airwalk » Sat Jan 16, 2016 7:53 pm

carulet wrote:I keep on crashing when I use a ShowDialog bind with UDF. Any help?!?!

Never worked with both ShowDialog or UDF, sorry. You're best off reading it up on github.
NOT ENOUGH

User avatar
Baldie
Wannabe Don
Wannabe Don
Posts: 1886
Joined: Sun Jul 11, 2010 12:42 pm

Re: [GUIDE] Autohotkey easy for everyone

Post by Baldie » Tue Mar 08, 2016 6:12 am

Good job bro.

User avatar
Airwalk
Game Administrator
Posts: 7160
Joined: Wed May 30, 2012 5:52 am

Re: [GUIDE] Autohotkey easy for everyone

Post by Airwalk » Sat Apr 23, 2016 1:53 am

Support per PM is still up.
NOT ENOUGH

User avatar
Cozy Wolfe
Mafia
Mafia
Posts: 389
Joined: Sat Oct 25, 2014 8:09 am
Location: Bandung, West Java.
Contact:

Re: [GUIDE] Autohotkey easy for everyone

Post by Cozy Wolfe » Sat Apr 23, 2016 4:06 pm

Well written guide!
Also, I just want to add a script which is useful for me. It's just like we send a random input in one key.

Code: Select all

Numpad8::

Random, numba, 1, 3



if numba = 1

   Sendinput t/ame coughs into his palm.{Enter}

else if numba = 2

   Sendinput t/ame sniffs.{Enter}

else if numba = 3

   Sendinput t/ame fixes his sunglasses.

return

Savini
Wannabe Don
Wannabe Don
Posts: 2621
Joined: Wed Aug 28, 2013 1:52 pm

Re: [GUIDE] Autohotkey easy for everyone

Post by Savini » Sun May 08, 2016 10:09 am

Helpful.

carulet
Gangster
Gangster
Posts: 134
Joined: Tue Oct 27, 2015 1:29 pm

Re: [GUIDE] Autohotkey easy for everyone

Post by carulet » Mon May 09, 2016 2:22 pm

Zacarii wrote:Well written guide!
Also, I just want to add a script which is useful for me. It's just like we send a random input in one key.

Code: Select all

Numpad8::

Random, numba, 1, 3



if numba = 1

   Sendinput t/ame coughs into his palm.{Enter}

else if numba = 2

   Sendinput t/ame sniffs.{Enter}

else if numba = 3

   Sendinput t/ame fixes his sunglasses.

return


You're better off not asking here. Even if you send him a PM asking for help, he won't help you out even though he says he's there to help you.

Post Reply

Return to “Player-Created Guides”

Who is online

Users browsing this forum: carulet and 4 guests