Sign in to follow this  
Followers 0
Lee Evans

HotKeySet and user defined functions

8 posts in this topic

I want to be able to press a key and pop up a message box which will display a given variables value within a script at the point that a hot key is hit. I just don't seem to be able to pass the variable as a parameter to the user defined function through the HotKeySend function.

Example script

;Press Esc to terminate script,

;Pause/Break to "pause",

;Shift pause to display message box with variable value

Global $Paused

Local $var1=1

HotKeySet("{PAUSE}", "_TogglePause")

HotKeySet("{ESCAPE}", "_Terminate")

HotKeySet("+{PAUSE}", "_ShowValue")

...Body of script here that contains $var1 which is set and then modified in the script...

Func _ShowValue($szName)

MsgBox(4096,"_ShowValue","Value is "&$szName)

EndFunc

I just don't seem to be able to pass the variable to the _ShowValue function.

If I use this I get nothing shown in the message box when Shift and pause are pressed

HotKeySet("+{PAUSE}", "_ShowValue")

If I use this

HotKeySet("+{PAUSE}", "_ShowValue ($val1)")

I get unknown function

If I use this

HotKeySet("+{PAUSE}", "_ShowValue ("&$val1&")")

I get unknown function

How do I pass the parameter to the user function?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This has been requested (as far as I remember) two times before.

I'm still waiting for (one of) the developers to stand up and say:

Let's make this happen

How I would like to use it:

HotKeySet( "hotkey", "function", "param1", "param2", ..., "param10")

Edited by SlimShady

Share this post


Link to post
Share on other sites

It is enough using global variants.

Share this post


Link to post
Share on other sites

It is enough using global variants.

<{POST_SNAPBACK}>

Not really. In my early days with AutoIt, I created a topic for my problem that could only be solved by using arguments/parameters.

Unless you, Ezzetabi, can give me a solution to my problem.

Because I still use that script. And I used the workaround of creating 15 functions.

Each hotkey, from 1 to 15, will launch Function1 to Function15 respectively.

Share this post


Link to post
Share on other sites

Global $hotkey
HotKeySet($hotkey, 'DoFunction')

Func DoFunction()
   Select
   Case $hotkey = 1
   Case $hotkey = 2
   EndSelect
EndFunc

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Global $hotkey
HotKeySet($hotkey, 'DoFunction')

Func DoFunction()
   Select
   Case $hotkey = 1
   Case $hotkey = 2
   EndSelect
EndFunc

<{POST_SNAPBACK}>

Nope. I guess you didn't read the whole topic.

That are nice examples. They don't solve this problem:

If you want to use a hotkey, the Hotkeyset can't tell a function which hotkey is pressed.

As in "an argument".

Example of what I would like to have:

HotKeySet($hotkey, DoFunction($x))

The $x variable will be some value I gave it.

And I can use one function that processes every hotkey that's set.

<{POST_SNAPBACK}>

That variable $x can be 1 to 15.

If the hotkey is pressed physically, the function receives a number from 1 to 15.

And I could use INIRead to do:

Func DoFunction($hotkey_num)
   $Command = INIRead($IniFile, "Commands", "HotKey" & $hotkey_num, "")
   If $Command <> "" Then Run($Command)
EndFunc

PS:

The syntax I posted on May 12, is invalid ofcourse.

Edited by SlimShady

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

There are a few reasons to have variables in hotkeys, this function is quite easy to do without however.

;Example script
;Press Esc to terminate script,
;Pause/Break to "pause",
;Shift pause to display message box with variable value
Global $Paused
Local $var1=1

HotKeySet("{PAUSE}", "_TogglePause")
HotKeySet("{ESCAPE}", "_Terminate")
HotKeySet("+{PAUSE}", "_ShowValue")

$x=1
$y=2
$z=3
while 1
   $x=$x+1
   $y=$x*$y
   $z=(3*$x)+($y/30)
sleep(1000)
tooltip($x & @cr & $y & @cr & $z,0,0)
WEnd


Func _ShowValue()
   $szName="x=" & $x & @crlf & "y=" & $y & @crlf & "z=" & $z 
   MsgBox(4096,"_ShowValue","Value is "&$szName)
EndFunc

func _terminate()
   exit
endfunc

func _togglePause()
   $paused=NOT $paused
   while NOT $paused
      sleep(10)
   WEnd
EndFunc

edit, oops forgot to copy _togglepause part

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Thanks for the help but I really wanted to not have to change the function each time I just wanted to pass the varaiable name to the function as a parameter.

I will just have to work around it until maybe the passing of parameters to the hot key function is allowed.

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