Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Basic Hotkey support


  • Please log in to reply
22 replies to this topic

#1 Jon

Jon

    Up all night to get lucky

  • Administrators
  • 10,630 posts

Posted 06 January 2004 - 01:18 PM

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.







#2 Jos

Jos

    ...

  • Developers
  • 23,287 posts

Posted 06 January 2004 - 02:59 PM

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.
  :)


#3 Jon

Jon

    Up all night to get lucky

  • Administrators
  • 10,630 posts

Posted 06 January 2004 - 03:09 PM

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.

#4 Jon

Jon

    Up all night to get lucky

  • Administrators
  • 10,630 posts

Posted 06 January 2004 - 04:57 PM

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

#5 jpm

jpm

    a Real GUI/debug lover

  • Developers
  • 9,749 posts

Posted 06 January 2004 - 05:04 PM

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:

#6 Jon

Jon

    Up all night to get lucky

  • Administrators
  • 10,630 posts

Posted 06 January 2004 - 05:06 PM

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, 06 January 2004 - 05:15 PM.


#7 Jon

Jon

    Up all night to get lucky

  • Administrators
  • 10,630 posts

Posted 06 January 2004 - 05:11 PM

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:

#8 scriptkitty

scriptkitty

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,274 posts

Posted 06 January 2004 - 05:11 PM

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, 06 January 2004 - 05:14 PM.

AutoIt3, the MACGYVER Pocket Knife for computers.

#9 Lemures

Lemures

    Prodigy

  • Active Members
  • PipPipPip
  • 153 posts

Posted 06 January 2004 - 07:09 PM

and autoit just keeps on getting better :whistle:

i love it, thanks Jon!!

#10 CyberSlug

CyberSlug

    Overwhelmed with work....

  • MVPs
  • 3,587 posts

Posted 06 January 2004 - 07:33 PM

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, 06 January 2004 - 07:39 PM.

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

#11 beerman

beerman

    Blurry

  • Active Members
  • PipPipPipPipPipPip
  • 7,419 posts

Posted 06 January 2004 - 07:55 PM

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

#12 scriptkitty

scriptkitty

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,274 posts

Posted 06 January 2004 - 09:15 PM

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:

Plain Text         
$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, 06 January 2004 - 09:17 PM.

AutoIt3, the MACGYVER Pocket Knife for computers.

#13 cmallett

cmallett

    Adventurer

  • Active Members
  • PipPip
  • 116 posts

Posted 06 January 2004 - 10:24 PM

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, 06 January 2004 - 11:06 PM.


#14 Jon

Jon

    Up all night to get lucky

  • Administrators
  • 10,630 posts

Posted 06 January 2004 - 11:04 PM

Feature or bug:

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

Oops. Bug.

#15 Jon

Jon

    Up all night to get lucky

  • Administrators
  • 10,630 posts

Posted 06 January 2004 - 11:12 PM

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:

#16 scriptkitty

scriptkitty

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,274 posts

Posted 06 January 2004 - 11:15 PM

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, 06 January 2004 - 11:18 PM.

AutoIt3, the MACGYVER Pocket Knife for computers.

#17 cmallett

cmallett

    Adventurer

  • Active Members
  • PipPip
  • 116 posts

Posted 06 January 2004 - 11:23 PM

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

#18 Jon

Jon

    Up all night to get lucky

  • Administrators
  • 10,630 posts

Posted 06 January 2004 - 11:25 PM


Feature or bug:

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

Oops. Bug.

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

#19 Jon

Jon

    Up all night to get lucky

  • Administrators
  • 10,630 posts

Posted 06 January 2004 - 11:28 PM

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:

#20 cmallett

cmallett

    Adventurer

  • Active Members
  • PipPip
  • 116 posts

Posted 08 January 2004 - 09:16 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users