Many thanks Chip. Before I send out a more refined version of the
code, I've two questions:
1. What is the difference between the OnKey* and OnKeyProcessed*
events? I have some understanding of the differences, or at least I
think i do, though I'd be grateful for further elucidation.
2. What happens to the value returned by the event handler, and will
the disconnection of the event from its handling function in any way
affect the process? On the face of it my OnKeyDown handler's
returning kdDiscard has the intended effect on the fate of the key
value that triggers said event, with or without the Disconnect
call,namely, the key is discarded whether the call comes before
kdDiscard is returned or afterwards. Again, more behind-the-scenes
info would be gratefully received.
Regards
Matt
At 16:04 13/06/2012, you wrote:
Hi Matt,
I don't read JS, but I did try to pick your questions out of the message:
nothing happens immediately when you disconnect from an event; that just
means you will not have your event handler called any more to handle those
events, so it's fine to do inside of an event handler.
If you want a double key hotkey, then I'd register the first key as a
hotkey. in the hotkey callback for the first key, I'd register the second
keys as hotkeys.
I'd also connect to the onKeyProcessedUp event in this first hotkey's
callback, and in the onKeyProcessedUp's callback I'd unregister all the
secondary hotkeys (so that as soon as any key was pressed after the first
hotkey, the secondaries would be unregistered, regardless of whether it was
one of them which was pressed or not).
This doesn't answer the question as to what will happen if they press
something after the first hotkey which isn't one of your second keys; you
didn't say what you want to happen in that case. In the way I just
described, the first hotkey just gets ignored by WE and Windows, and the
second key, if not one of your secondary keys, will be processed by them.
If the second key is one of yours, then it too will be ignored by WE and
Windows.
hth,
Chip
> -----Original Message-----
> From: MJ Williams [mailto:[email protected]]
> Sent: Tuesday, June 12, 2012 11:10 PM
> To: [email protected]
> Subject: connecting and disconnecting events and callbacks
>
> Hello,
> I'm trying to create a two-stage or double-stroke hotkey, e.g.
> Insert-x followed by a series of options offered by keys 1 to
> 9. Here's a rough idea of how I am going about it in code at
> the moment:
> // start JS code
> 0: var conHandle = null;
> 1:
> 2 function test ( ) {
> 3 conHandle = ConnectEvent (Keyboard, "OnKeyDown", "OnKeyDown" )
> 4 }
> 5
> 6 function OnKeyDown (key, mod) {
> 7 if ( key == vk_1 ) {
> 8 Speak ("done");
> 9 Disconnect( conHandle );
> 10
> 11 return kdDiscard;
> 12 }
> 13 }
> // end js code
>
> A variant of this code runs as intended, even though the
> call to disconnect (at line 9) comes before the callback
> returns its disposition, and I would have thought that
> disconnecting the connecting event at that point would
> disrupt the returning of the key disposition. I would like
> to know exactly what goes on behind the scenes when a
> callback tied to an event of this kind is invoked. More
> specifically, where does the key disposition value returned
> by the callback end up, and what happens (at least in theory)
> when the disconnect method is invoked before the callback has
> completed execution?
>
> If anyone has a more elegant solution to my original idea I
> would be grateful for any pointers.
>
> Regards
> Matt
>