Sign in to follow this  
Followers 0
coasty

Not possible to pass var to function using HotKeySet?

4 posts in this topic

Hi,

Doing this is giving me a syntax error on compile;

HotKeySet("{ENTER}","ButtonEventHandler($KEY_ENTER)")

Can I not pass a var to ButtonEventHandler using HotKeySet? Is there a work-around for this?

Thanks

Share this post


Link to post
Share on other sites

The only way that you can do it is by calling a function within a function.

Example:

Global $KEY_ENTER

HotKeySet("{ENTER}","ButtonEvent")

Func ButtonEvent()
   ButtonEventHandler($KEY_ENTER)
EndFunc

Note: Be sure to declare the var you going to use as GLOBAL


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Not possible to pass var to function using HotKeySet?

Nope. But it all depends what you want to do.

In my case, I use hotkeys to set a variable named $Hotkey and $Hotkey is evaluated at different points parts in the program like so:

If $Hotkey Then ConsoleWrite("Number "&$Hotkey&" is the winner!")

And here's some typical code to setup the hotkeys ... read the comments!

Func Set_HOTKEY()
For $i = 1 to 8; Keys 1 to 8 on the keyboard
  HotKeySet($i,"Def_HOTKEY"); Notice all point to the same function - There's a trick!
Next
EndFunc

Func Def_HOTKEY()
If @HotKeyPressed > 0 And @HotKeyPressed < 9 Then; @HotKeyPressed can be used to set a variable
  $Hotkey = @HotKeyPressed; In this case the variable is the hotkey pressed. You could use switch
Else; and set up different variables/functions depending on what you want to do and what key is
  $Hotkey = 0; pressed ... 
EndIf; The check on the first line is superfluous but you never know;)
EndFunc

Don't forget to set Global $Hotkey at the top of your program!

Edited by Celeri

I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

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