Jump to content

Keboard Handling


Recommended Posts

A new-comer thanks:

1. CyberSlug, for providing a pointer from the TextPad forum to AutoIt and this forum; and

2. AutoIt, for, well, being, and for providing a way to spend many happy hours saving a few troublesome seconds.

As a trivial task, I am giving myself an alternative way to move and resize the document windows in TextPad (and, in principle, any other MDI application). (Plainly I haven't got enough to keep me busy.) I give control to keyboard handlers in AutoIt, with

HotKeySet ( "{AKey}" , "AKeyHandler" )
  ...
  HotKeySet ( "{ZKey}" , "ZKeyHandler" )

  HotKeySet ( "{ENTER}", "Accept" )
  HotKeySet ( "{ESC}"  , "Cancel" )

  Sleep (10000)

This puts my editing session into a sort-of mode (key strokes go to AutoIt instead of TextPad). Unfortunately, I can't see that it's in a mode, as I can't find a way to change the mouse cursor. A splash screen would be a bit over the top. Thus it's in a hidden mode, which is, of course, a Bad Thing.

It's worse than that: the mode is only a sort-of mode because key events that I don't catch with HotKeySet go to the application underneath (TextPad). This gets somewhat confusing when I forget to terminate the mode.

So I ask:

1. Can I change the mouse cursor? There doesn't seem to be a MouseSetCursor to match MouseGetCursor.

2. If I have passed control to keyboard handlers with HotKeySet and Sleep, can I capture /all/ key presses (so that I can throw away the ones I don't want).

3. Can I pass a "user information" parameter to HotKeySet, which AutoIt passes to the handler, so that one handler can handle more than one key event, and be able to distinguish between them. (Well, the answer to this, I think, is No. So it's an enhancement request.)

Thanks.

Link to comment
Share on other sites

1) You can display a ToolTip (Any OS) or a TrayTip (2000/XP only)

2) You can't trap letters or numbers without a modifier (Shift, Alt, Control or WinKey).

3) See code:

HotKeySet("!z", "ZHandler")
HotKeySet("!a", "AHandler")

Func ZHandler()
   HotKeyHandler("!z")
EndFunc

Func AHandler()
   HotKeyHandler("!a")
EndFunc

Func HotKeyHandler($szKey)
    If $szKey = "!z" Then
        MsgBox(4096, "Alt+z", "Alt+z was pressed")
    ElseIf $szKey = "!a" Then
        MsgBox(4096, "Alt+a", "Alt+a was pressed")
    Else
        MsgBox(4096, "Unhandled event", "Unhandled hotkey")
    EndIf
EndFunc
Link to comment
Share on other sites

A tooltip is used in the HotKeySet documentation example, in fact :whistle: You could also change the title of the TextPad window.

How exactly do you want to move the windows? With mouse or keyboard? Do you want to do something like tile selected windows horizontally?

1) There is no MouseSetCursor (yet).....

2) To capture all keypress, you'd need to set up a hotkey for each one you want to trap; however, there is a limit of 64 active hotkeys per script.

3) The function that you call via HotKeySet (such as "AKeyHandler") cannot take any parameters, but you can use global variables to pass data between functions.

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

Thanks for your response, Valik.

1) You can display a ToolTip (Any OS) or a TrayTip (2000/XP only)

Ah. I hadn't thought of it. I'll use a ToolTip for the moment.

2) You can't trap letters or numbers without a modifier (Shift, Alt, Control or WinKey).

Indeed. I wasn't trying to. :whistle:

3) See code:

HotKeySet("!z", "ZHandler")
HotKeySet("!a", "AHandler")

Func ZHandler()
  HotKeyHandler("!z")
EndFunc

Func AHandler()
  HotKeyHandler("!a")
EndFunc

Func HotKeyHandler($szKey)
   If $szKey = "!z" Then
       MsgBox(4096, "Alt+z", "Alt+z was pressed")
   ElseIf $szKey = "!a" Then
       MsgBox(4096, "Alt+a", "Alt+a was pressed")
   Else
       MsgBox(4096, "Unhandled event", "Unhandled hotkey")
   EndIf
EndFunc
Yes, I do that sort of thing already. But to handle 20 keyboard events I still need 20 handlers.
Link to comment
Share on other sites

Thanks, CyberSlug.

A tooltip is used in the HotKeySet documentation example, in fact B)  You could also change the title of the TextPad window.

Belive it or not, I've read the documentation. :whistle: But I missed that bit. The indication of the mode needs to be where my eyes are looking, so I'll make do with a ToolTip until MouseSetCursor is available...

How exactly do you want to move the windows? With mouse or keyboard?  Do you want to do something like tile selected windows horizontally?

With the keyboard; I'm a musophobe who remembers Westrex Teletypes with fondness! I want to rearrange my windows individually, using various obvious and obscure key combinations to move and resize them.

1)  There is no MouseSetCursor (yet).....

For the wish list, then.

2)  To capture all keypress, you'd need to set up a hotkey for each one you want to trap; however, there is a limit of 64 active hotkeys per script.

3)  The function that you call via HotKeySet (such as "AKeyHandler") cannot take any parameters, but you can use global variables to pass data between functions.

Global variables won't help; there's no way to set them after a keyboard event has occurred and before the handler is called. So HotKeySet with user data is for the wish list as well.
Link to comment
Share on other sites

Possible workaround for the MouseSetCursor issue:

When TextPad is running, Send("^+6"). This should make the mouse cursor look like a finger pressing a key. Look up "How to Type International Characters" in TextPad's help file to see why this works....

Good Luck

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

Possible workaround for the MouseSetCursor issue:

When TextPad is running, Send("^+6").  This should make the mouse cursor look like a finger pressing a key.

That deserves a prize for obscurity! It begins to work. Unfortunately, it buggers up screen updating until a key not captured by the AutoIt script is pressed (when the finger disappears). And if the script terminates without such a key being pressed, TextPad waits for another keystroke before it will do anything else.
Link to comment
Share on other sites

Then say Send("{Esc}") at the very end of your AutoIt script :whistle:

Good try!

But:

{ESC} is one of the keys the script handles, so it causes an infinite recursion. I tried something else instead.

Completing the two-key sequence doesn't fix the screen updating problem. It seems that if you send TextPad a prefix key, then until you send it another key it doesn't update anything other than the active document window.

And sending the prefix key causes some other mysterious keyboard-handling problem that I haven't been able to analyse.

Edited by ben_josephs
Link to comment
Share on other sites

Unset the hotkey first, then send the key, then reset it.

HotKeySet("{ESC}")   ; Unset
Send("{ESC}")   ; Send the keystroke
HotKeySet("{ESC}", "YourFunction")   ; Reset the hotkey

CyberSlug's trick for sending hotkey keystrokes without infinite recursion.

Link to comment
Share on other sites

Unset the hotkey first, then send the key, then reset it.

HotKeySet("{ESC}")  ; Unset
Send("{ESC}")  ; Send the keystroke
HotKeySet("{ESC}", "YourFunction")  ; Reset the hotkey

CyberSlug's trick for sending hotkey keystrokes without infinite recursion.

Thanks for pointing that out.

But in this case I can simply use a different keystroke: one that isn't captured by the script (so AutoIt passes it to TextPad) and that doesn't complete a two-key TextPad short cut.

I think that any solution using two-key TextPad short cuts will suffer from the screen updating problem.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...