Sign in to follow this  
Followers 0
nexguy

How to execute script with a hotkey?

8 posts in this topic

I must have searched through this entire site and I cannot find anything about this.

I used to do it with AutoHotkey, but my new company uses AutoIt. It looks great! But how can I execute a script with a hotkey...like "windows"+"z" or something?

Or maybe I missed it and I am blind?

Thank you!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Ha I'm not gonna call you blind... :)

Check out HotKeySet () in the help file, and _IsPressed()

Welcome to the forum

Edited by someone

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try This:

#InCludE <MiSC.aU3>
While 1
If _IsPressed("01") Then ExecuteScript()
Sleep(50)
WEnd

Func ExecuteScript()
;do your script here!
EndFunc
Edited by R6V2

Share this post


Link to post
Share on other sites

Ah, so I have to create a key catching script that runs all the time, to catch my hotkey presses?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ah, so I have to create a key catching script that runs all the time, to catch my hotkey presses?

Try what I did, set it in a loop, until it is pressed, maybe try this:

#include <misc.au3>
Do
Sleep(50)
Until _IsPressed("01")

;do your code here.
Edited by R6V2

Share this post


Link to post
Share on other sites

This would be for all day use. For example, I have a user that wants to be able to press a button and it types her e-mail address. Or it runs a quick test script for her.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

There are differences between IsPressed and Hotkeyset, and I would suggest trying out Hotkeyset... it sounds more like what you need.

But either way, you need to tell your script to do something while 'listening' for a certain keypress, aka a loop. The example in the help file for Hotkeyset uses a While/Wend loop, which will keep the script alive and listening until the user kills it.

Edited by someone

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Or you make a shortcut to the script at the desktop and assign a hotkey to it by right clicking and choosing properties :)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0