Sign in to follow this  
Followers 0

Basic Hotkey support

23 posts in this topic

#1 ·  Posted

Please give this unstable version a test:

http://www.hiddensoft.com/autoit3/files/unstable/

HotKeySet("key", "function")

"key" is in the same format as the Send() function (i'll update filecreateshortcut for this if it works ok). eg. Ctrl+Alt+d:

HotKeySet("^!d", "test")
Sleep(10000)


Func test()
    MsgBox(0, "Test", "test called")
EndFunc

Using a blank function will unset a previous hotkey. Keys are executed in order one at a time and about 64 hotkey presses are buffered.


Uber promo code for money off the first ride: uberautoit

Share this post


Link to post
Share on other sites



#2 ·  Posted

Works great !!!

Put this at the beginning of a large install script that I would like to be able to cancel:

HotKeySet("^!x", "Fin")

And this at the bottom:

Func Fin()

MsgBox(0, "Install Stopped", "Installation stopped")

exit

EndFunc


Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted

I'll have to add a "Pause" function as well so that we can pause/unpause the scripts via keys and that should be that.


Uber promo code for money off the first ride: uberautoit

Share this post


Link to post
Share on other sites

#4 ·  Posted

Doesn't appear so. Docs don't specify but you seem to need at least one modifier key (ctrl, alt, win, shift)


Uber promo code for money off the first ride: uberautoit

Share this post


Link to post
Share on other sites

#5 ·  Posted

if HotKeySet("^d", "test") = 0 then exit   ; Call function test() on ctrl+d
Sleep(10000)

Func test()
global $i
$i=$i+1
SplashTextOn("title", $i, 300, 100, 100+10*$i);
EndFunc

That look great

You must check that ^ ! is in the hotkey because no error return an no hotkey either

PS I have a AutoItV2toV3 working based on 3.0.84 do you want to test it :whistle:

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Doesn't appear so.  Docs don't specify but you seem to need at least one modifier key (ctrl, alt, win, shift)

Actually, scratch that - I still had a bit of code that forces ctrl+alt if nothing else is given, works for single keys now.

Edit: re-uploaded.

Edited by Jon

Uber promo code for money off the first ride: uberautoit

Share this post


Link to post
Share on other sites

#7 ·  Posted

That look great

You must check that ^ ! is in the hotkey because no error return an no hotkey either

PS I have a AutoItV2toV3 working based on 3.0.84 do you want to test it :whistle:

Thanks, JP B)

Sure, we'll test - send it me and I'll pop it in the /unstable directory :angry:


Uber promo code for money off the first ride: uberautoit

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I like it so far, um yea, no single key. Actually better that way I think. Docs should point it out. Testing continues on the TNT version. :whistle:

Oh yea, the new help file still has the ] backwards:

FileOpenDialog ( "title", "init dir", "filter", [options[ )

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#9 ·  Posted

and autoit just keeps on getting better :whistle:

i love it, thanks Jon!!

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

EDIT: Nevermind! It was because I has set the BIOS to emulate the Fn key on the external keyboard when pressing rightCtrl+rightAlt.

I'll leave the post in case anyone else has this problem.

============

External keyboard weirdness:

I'm using a laptop* with an external PS/2 keyboard. Hotkey presses such as Ctrl+Alt+D do not work if typed on the external keyboard. However, they work on the laptop keyboard.

I've noticed a similar problem with BlockInput(1): Ctrl+Alt+Delete only registers if pressed on the laptop's keyboard.

It's not a big deal, but I was just wondering :whistle:

*Toshiba Tecra 8000 laptop with Windows XP Pro sp1

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#11 ·  Posted

ok just for laughs. i had a dell latitiude xpi 166mhz. yeah slug i know what you are saying. it ain't just you. if you play with the laptop keyboard, you maybe suprised what you will find. cause that lap top had a whole bunch of predefined kes from poping out the cd rom to volume mute. but one question before i amke an ass of myself. do it have a fn key on these new laptops? if no them maybe a certain combos will be activated by certain pressings.


 

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

A few single key combos seem to work. On winXP, #d still activates show desktop and doesn't pass it to AutoIt, but no other real problems so far.

This is vey fun to play around with. I chained a few together. rest :whistle:

$x=1
HotKeySet("r", "test")  ; Call function test() 

while winexists("unstable","")
sleep(1000)
$x=$x+1
wend

Func test()
    HotKeySet("e", "test1") 
EndFunc
Func test1()
    HotKeySet("e") 
    HotKeySet("s", "test2") 
EndFunc

Func test2()
    HotKeySet("s") 
    HotKeySet("t", "test3") 
EndFunc
Func test3()
    MsgBox(0, "Test", "Test called "&$x)
EndFunc

Feature or bug:

HotKeySet("^r", "test"); sets it
HotKeySet("^r"); removes it
HotKeySet("^r", ""); crashes
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Doesn't appear so. Docs don't specify but you seem to need at least one modifier key (ctrl, alt, win, shift)

Not true, at least under WinXP (and by extension, probably WinNT and Win2k as well). Virtually any hotkey can be activated with RegisterHotkey(), even an unmodified letter key. For example, this works in AutoHotkey:

d::

MsgBox, yes

; This reveals that the hotkey is registered rather than handled by the hook:

ListHotkeys

return

You must check that ^ ! is in the hotkey because no error return an no hotkey either

Can anyone confirm that this affects Win9x? Because obviously it doesn't apply to WinXP.

On winXP, #d still activates show desktop and doesn't pass it to AutoIt, but no other real problems so far.

You need a keyboard hook to override Windows-reserved hotkeys on an individual basis (i.e. they're already registered by the Explorer, so another app can't easily "steal" them).

A few things that might be problematic with this feature, which I mentioned before:

1) Infinite loops. Here is an oversimplified example (real world examples are usually more insidious and happen when you don't even realize you've done it):

^!d::Send, ^!d ; Infinite loop, possible computer lock-up or other bad things.

Although the above example might not produce a lock-up, a more complex Send that sends more keys could very well do that, or cause your apps to misbehave due to the steady stream of keys being sent to the ever-changing active-window as the user tries to extricate himself from a computer that's seemingly become unresponsive.

2) Any hotkey that uses the Send command to Send its own modifiers might produce unexpected results. Another over-simplified example:

^!d::Send, {CtrlDown}

The above will not work as expected (without additional code to handle it) because when the user physically releases the hotkey, the control key will be back in the up position.

3) Minor: Without additional code to handle it, hotkeys that send their own modifiers (e.g. CTRL or ALT) will not be repeatable unless the user releases and presses the modifiers again. This is because the modifiers will be in the up position after the Send() even though the user may still be physically holding them down.

There may be a few other issues.

Edit: Another issue (Jon, you may have already added code to handle this): Without additional code, the hotkey's own modifiers will affect the keys sent by the send command. Example:

^!d::Send, abc ; This might really send ^!a^!b^!c

Edited by cmallett

Share this post


Link to post
Share on other sites

#14 ·  Posted

Feature or bug:

HotKeySet("^r", "test"); sets it
HotKeySet("^r"); removes it
HotKeySet("^r", ""); crashes

Oops. Bug.

Uber promo code for money off the first ride: uberautoit

Share this post


Link to post
Share on other sites

#15 ·  Posted

I'm thinking of leaving it as it is tbh, even if there are a few snags, my goal isn't a hotkey app and the amount of rewrites I imagine are required to fix these snags wouldn't be insignificant.

If there are easy fixes though feel free to comment - I'm useless at working stuff out from others' code. :whistle:


Uber promo code for money off the first ride: uberautoit

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

infinite loops can be a problem, ex:

HotKeySet("!r", "test")  
sleep(10000)

Func test()
    sleep(1000)
    send("Repeat!r")
EndFunc

Single keys will be the real issue, but I think it is a really nice feature as it stands now. I will try to check compatibility and bugs on a few other OSs.

Right now I feel like a kid in a candy store :whistle:

also worth noting, at least in the documentation, is not to use caps.

HotKeySet("+r", "test") <> HotKeySet("R", "test")

Also worth noting, the example above should only work for 10 seconds, but if you start the loop going, it will continue forever.

This is a little strange as well.

HotKeySet("R", "test")  
sleep(10000)

Func test()
    sleep(1000)
    send("Repeat")
EndFunc

Edit...Oh, if I didn't express more clearly, I really like this, even exactly how it is. I think all that is really needed is a warning label B)

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#17 ·  Posted

Relatively minor issue: user physically releasing the hotkey modifiers in the middle of a Send operation might mess up the send. Example:

^!d::Send, ^{Left 15}

If the user physically releases the hotkey modifiers during the send, some of the left-arrows probably won't be properly modified by the Control key. But this is probably an easy fix because AutoIt just needs to check the state of the modifiers before every keystroke rather than before every new symbol (which it may already do, I'm not sure).

(and in case you didn't see my edit above)

Another issue (Jon, you may have already added code to handle this): Without additional code, the hotkey's own modifiers will affect the keys sent by Send(). Example:

^!d::Send, abc ; This might really send ^!a^!b^!c because the user is physically holding down the keys

Share this post


Link to post
Share on other sites

#18 ·  Posted

Oops. Bug. On seconds thoughts, I thought you meant windows crash, not AutoIt error message, so feature.

Uber promo code for money off the first ride: uberautoit

Share this post


Link to post
Share on other sites

#19 ·  Posted

Relatively minor issue: user physically releasing the hotkey modifiers in the middle of a Send operation might mess up the send.  Example:

^!d::Send, ^{Left 15}

If the user physically releases the hotkey modifiers during the send, some of the left-arrows probably won't be properly modified by the Control key.  But this is probably an easy fix because AutoIt just needs to check the state of the modifiers before every keystroke rather than before every new symbol (which it may already do, I'm not sure).

(and in case you didn't see my edit above)

Another issue (Jon, you may have already added code to handle this): Without additional code, the hotkey's own modifiers will affect the keys sent by Send(). Example:

^!d::Send, abc ; This might really send ^!a^!b^!c because the user is physically holding down the keys

Hmmm, IIRC it assumes no modifiers are already pressed and the only checking is for the {ALTDOWN} type situations. A few GetKeyState() littered around may work. Thanks. :whistle:

Uber promo code for money off the first ride: uberautoit

Share this post


Link to post
Share on other sites

#20 ·  Posted

I'm surprised no one said a word about this, so I'll post it again because I think it's relevant:

Doesn't appear so. Docs don't specify but you seem to need at least one modifier key (ctrl, alt, win, shift)

You must check that ^ ! is in the hotkey because no error return an no hotkey either

Not true, at least under WinXP (and by extension, probably WinNT and Win2k as well). Virtually any hotkey can be activated with RegisterHotkey(), even an unmodified letter key.

I know Win9x is slightly more limited in which hotkeys can be registered. But even in that OS, I'm under the impression that just about any key can be registered.

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