-
Notifications
You must be signed in to change notification settings - Fork 28
Making and Removing Hotkeys
Hooked attempts to simultaneously be easy to use, but powerful. The creation and destruction of hotkeys is where this is most apparent.
####Adding hotkeys
The basic way to make a hotkey is:
hk.Hotkey(["RCtrl","W"],foobar)
Note that in the above, hk
is an instance of hook. The Hotkey function takes a list of keys (RCtrl+W) as the first argument. The second argument is a function. These are the required arguments. The id of the hotkey is returned (as an int).
The full, complex function in use:
hk.Hotkey( ['LCtrl', [345,749], "Wheel"], foo, ("I am an arg",23) )
Okay, lets digest that. The "keys" used are more complex (I am counting a point as a "key"). Again, foo is a function that is referenced. The next argument is the arguments of foo that you want to pass when the hotkey is called. I chose a tuple as the way to pass args.
####Remove hotkeys
Removing hotkeys is as easy as adding them. Any of the following will remove the second hotkey from above.
hk.RemHotKey(1) #this removes the second hotkey (we start counting at 0 of course) hk.RemHotKey(foo) #this removes based on the function hk.RemHotKey(['LCtrl', [345,749], "Wheel"]) #or, of course, remove based on the key list.
That is it! You now know how to make functions work. How about learning the keys?