Jump to content

How to execute script with a hotkey?


Recommended Posts

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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...