Sign in to follow this  
Followers 0
Guest zezzagio

Getting hotkeys bindings

4 posts in this topic

There is a way to get the function a hotkey is bound to?

For example, the manual suggests:

; capture and pass along a keypress

HotKeySet("{Esc}", "captureEsc")

Func captureEsc()

; ... can do stuff here

HotKeySet("{Esc}")

Send("{Esc}")

HotKeySet("{Esc}", "captureEsc")

End Func

I'd like to have a function, let say GetHotKeyBinding, in order to be able to do:

Func captureEsc()

; ... can do stuff here

$oldFunc = GetHotKeyBinding("{Esc}")

HotKeySet("{Esc}")

Send("{Esc}")

HotKeySet("{Esc}", $oldFunc)

End Func

This is just an example, but I think such a function could be useful in some other circumstances too.

Ciao.

Share this post


Link to post
Share on other sites



Why not just keep track of an array or some variables each time you set a hotkey? I just don't see the point of doing a reverse lookup with a hotkey, since the only use I see of it would be to change it from the function that was called with the original hotkey. And in that case there is no need to do a reverse lookup, because you already know which function it's in (seeing as how it's being coded in that function.)

A small UDF could to the trick for whenever you set a hotkey. Or better yet, make a UDF that keeps track of a global array of hotkeys, and handels the setting and releasing of hotkeys.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

>Why not just keep track of an array or some variables each time you set a

>hotkey?

And why doesn't AutoIt do it for me, as for "why"?

>I just don't see the point of doing a reverse lookup with a hotkey, since the only

>use I see of it would be to change it from the function that was called with the

>original hotkey. And in that case there is no need to do a reverse lookup,

>because you already know which function it's in (seeing as how it's being coded

>in that function.)

I could say "Emacs has it, that's enough" ;-). A reverse lookup is needed in AutoIt code in all situations it's needed in Emacs code; for example, simply to show the user what is bound to what.

You are right, though, I did chose the wrong reverse lookup in my example. This one is better:

Func captureSomekey()

; ... can do stuff here

$oldKey = GetFuncHotKeyBinding("captureSomekey")

HotKeySet($oldKey)

Send($oldKey)

HotKeySet($oldKey, "captureSomekey")

End Func

I know I'm here, but I don't know what caused me to be here.

And, for the other one:

HotKeySet("!c", "ChangeFunc")

HotKeySet("!f", "Func1")

Func Func1()

MsgBox ( 1, "Func1", "Hi, Func1 here!")

End Func

Func Func2()

MsgBox ( 1, "Func2", "Hi, Func2 here!")

End Func

Func ChangeFunc()

If GetKeyHotKeyBinding("!f") = "Func1" Then

HotKeySet("!f")

HotKeySet("!f", "Func2")

Else

HotKeySet("!f")

HotKeySet("!f", "Func1")

EndIf

End Func

(Actually, GetKeyHotKeyBinding should return an array, I guess.)

The truth, though, is that I just don't see the point of not having reverse lookup functions for hotkeys. You have a set function, of course you have to have a function to retrieve what you have set. Why shouldn't it be there?

>A small UDF could to the trick for whenever you set a hotkey. Or better

>yet, make a UDF that keeps track of a global array of hotkeys, and handels the

>setting and releasing of hotkeys.

Some way is better than no way at all, and this is definitely a way. I still think, though, that AutoIt should do the job for me, for it's in a better position than me to do it.

Ciao.

Share this post


Link to post
Share on other sites

I have created a UDF that allows you to track HotKey changes including new HotKeys, removing HotKeys, and re-defining a HotKey to a new function. In addition, you can do a lookup (take a hotkey and get back the function it is linked to) or a reverse lookup (take a function name and get back an array of all hotkeys that link to that function.) See the thread here, or download it from my project web page (see my signature link.)


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

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