PDA

View Full Version : AutoHotkey (Binding) Tutorial



Walden_Schmidt
13th February 2016, 08:51 AM
AUTOHOTKEY TUTORIAL

http://i.imgur.com/EJGWCwo.png
I browsed the forums for a tutorial on how to bind keys, so a command would be executed easier, and found jack squat. I'll try to make this short and simple. Whoever doesn't want to read can skip straight to the coding at the bottom. Sorry If I made this too beginner-like, but I want everyone to be able to follow the instructions.

This is a Windows tutorial, If you have Linux or Mac, the procedure is pretty much the same.

You will find all of the coding at the bottom of the topic (Suggestions are welcome)

For this tutorial I will be using AutoHotkey and everything is pretty much simple.


Installation

1. Download the latest version of AutoHotkey(click me) (https://autohotkey.com/) from the official website.
1.1 When the setup opens, choose Custom If you want to install it to a custom folder or Express to install it to the windows bootable space.
1.1.1 If you chose Custom, select Unicode 32-bit, as that is all we would need. If you choose the 64-bit version you may get samp problems & crashes.
1.2 At the next window MAKE SURE the first option: Install script compiler is selected. You may deselect the others, it's really just personal preference. If you don't select the third one you'll have a separate autohotkey taskbar, while if it's selected it will be hidden/minimized away from the taskbar, so it's just easier to work with.
1.3 When the setup completes, exit the installation.


Scripting

Before you begin the actual scripting, you need to get to know your new environment. Whenever you right click anywhere on an empty space on the desktop and choose New, you have a new option: Autohotkey Script


http://i.imgur.com/3tW15mV.png

Let's begin and create a new AutoHotkey script. Name your script whatever you want and open it by right-clicking and choosing Edit Script. A notepad file will open and a bunch of crap will be written. Delete everything as it's unnecessary.

Here's the standard AutoHotkey format:
Key:: SendInput command{enter}

It's pretty self-explanatory. You put {enter} If you want the process to automatically 'press Enter' at the end of the command or you can remove {enter} and whenever that hotkey is pressed the chatbox with the command will appear, but Enter will not be pressed.

{enter} basically means that the button Enter will be pressed.

Another common mistake that is made is with the exclamation mark (!)
If you do:

^1:: SendInput t/s Put your hands in the air!! {enter}

and do Ctrl + 1 your hotkey will crash and possibly your game will freeze/crash or you might not just get the exclamation marks, they won't appear. That's why you need to put exclamation marks in these brackets {}, so it's:

^1:: SendInput t/s Put your hands in the air{!}{!} {enter}

Here's a list of all the keys (https://autohotkey.com/docs/KeyList.htm). But for this tutorial we will be using ! & ^. ^ - Ctrl ! - Alt.


So, let's say we type:

!2 ::SendInput t/me likes stuff.{enter}

After typing that, close & save the notepad file, press right click on the script and choose Compile Script. A new application with a green icon should be created. Double click it, there should be no errors, open notepad or sarp and when you press Alt + 2 you should get t/me likes stuff. or Name_Surname likes stuff..


http://i.imgur.com/uRUp1gA.png

------------------------------------------------------------------------------------------------------------------------------------

http://i.imgur.com/sdigdOj.png

------------------------------------------------------------------------------------------------------------------------------------

http://i.imgur.com/r3LYetQ.png





That's pretty much the basics. You use ! or ^ for Alt or Ctrl and the keys you add is the new hotkey.

Now, to cover every possible hotkey you might need, I will also explain the timer. To add a timer, use the command Sleep . Make sure you write Return at the end If you want the script to stop after a specific moment. This is really useful for the LSPD as the Miranda Rights are pretty long to type and you mustn't spam. Here's how you should do it.

Keep in mind that you can only type about 86 characters before the rest disappears as that's the SARP limit

!5::
SendInput tYou have the right to remain silent.{enter}
Sleep 2000
SendInput tAnything you say can and will be used against you in the court of law.{enter}
Sleep 2000
SendInput tYou have the right to an attorney, bla bla bla{enter}
Sleep 2000
return

So, what this does is it executes the first command line after the hotkey Alt + 5 has been pressed, waits 2 seconds (1.000 miliseconds = 1 second) and executes the third command. You can type as much as commands as you want after Key::. If you have fair basic programming knowledge in C++ you would know that every function starts with a { and ends with a }. Take it as if there's a { after the Key:: and a } after Return.

To avoid repetition, you may want to shorten your code.
Instead of typing

!5::
SendInput t/me reaches into his pockets and takes out some stuff.{enter}
SendInput t/do The stuff would be the shit {enter}
SendInput t/me bla bla{enter}

You can do it in 1 line. It's kinnda like cout (http://www.cplusplus.com/reference/iostream/cout/). So it would look like:

SendInput t/me reaches into his pockets and takes out some stuff.{enter}t/do The stuff would be the shit {enter}t/me bla bla{enter}

You can even be creative and original and think of new ways of scripting. You can use {space} which gives you a space and allows you to type. Then it would enter the command. Here's an example.

!5::
SendInput t/me reaches into his pockets and takes out{space}
Sleep, 7000
SendInput {space}and does something with it {enter}

You can use this to take out a specific weapon, for example an AK or M4 or MP5, so you just type the word.

You can even use dynamic variables to suit your situation. Here's an example:
!2::
if (tCrap = 1)
{
Sendinput t/me pulls down his pants and takes a crap.{enter}
tCrap = 0
}
else
{
Sendinput t/me pulls down his pants and takes a piss{enter}t/piss{enter}
tCrap = 1
}
return


You know, be creative. Here are some codes & an adjusted Miranda Right command for those who just want the codes:


SOME BASIC CODES


!2::SendInput t/enter{enter}t/exit{enter}

!4::
SendInput t/me reaches into his backpack, takes out{space}
Sleep, 5000
SendInput {space}and turns the safety off. {enter}
return

!5::
SendInput tYou have the right to remain silent.{enter}
Sleep 2000
SendInput tAnything you say can and will be used against you in the court of law.{enter}
Sleep 4000
SendInput tYou have the right to an attorney after initial processing has been completed.{enter}
Sleep 4500
SendInput tIf you cannot afford one, one will be provided for you.{enter}
Sleep 3500
SendInput tDo you understand these rights as I have just read them to you?{enter}
return

!6::SendInput t/lock{enter}

Any fixes, problems & suggestions are always welcome.

Donna_Taylor
13th February 2016, 09:06 AM
I guess you copied this tutorial from another server, I saw it on some forums ages ago.

Walden_Schmidt
13th February 2016, 09:15 AM
No, I wrote this all myself, wtf dude, gimme a link so I can see

Donna_Taylor
13th February 2016, 10:41 AM
No, I wrote this all myself, wtf dude, gimme a link so I can see

Well if that's the truth, although it's a decent nice tutorial.

Good job, might be my bad.