Hi David,
What is best to use depends on whether you wish to restrict Window-Eyes from
speaking when the key is pressed, or you may not want Window-Eyes to see it
at all at times, or you may not want the underlying program to see the
keystroke at times, or you just want your app to also know about it but not
prevent anyone else from seeing it.
The possibilities to work with are the events of a key object (which you
would have to create a key object for each key you want to handle, and then
use the connectEvent() command to indicate which event you are interested in
and which function of yours is to be called).
Or, for all keys, you can use the keyboard object events (where you don't
create any object first, but you will use connectEvent with the appropriate
event, and you'll get called for every key and you must test on which key it
was). Or you can use the application object onCursorKey event: which is a
lot like the keyboard event in that you'll get called for every keystroke
(but only those which falls into the group window-eyes knows as "cursor
keys"; you can see this group of keys by going into the main control panel,
find the main topic in the treeview for cursor keys, and tab over and go
down the list and you'll see all the keys which fall into this group).
I'm going to guess you have a couple of specific keys you want to handle
(and yes, while you have to define a key object for each key and store it in
a global variable), you can share a command event handler for all of them).
I did this in one app where I wanted Window-Eyes to not say anything when an
up arrow or down arrow was pressed, and my app would say something instead.
The onKeyDown and onKeyUp events of the key objects allow you to control
what window-eyes does with the key, and you can also stop the program from
seeing it if you need to. Here's a little code from my app that does this:
Set downArrow = keyboard.key("down arrow")
downArrowEvent1 = ConnectEvent(downArrow, "onKeyDown", "OnArrowKey")
downArrowEvent2 = ConnectEvent(downArrow, "onKeyUp", "onArrowKey")
Set upArrow = keyboard.key("up arrow")
UpArrowEvent1 = ConnectEvent(upArrow, "onKeyDown", "onArrowKey")
UpArrowEvent2 = ConnectEvent(upArrow, "onKeyUp", "onArrowKey")
Function onArrowKey(ByVal VirtualKeyCode, ByVal KeyModifiers)
' event handler
onArrowKey = kdPass Or kdSilence ' give to program, but don't allow WE to
process
End Function
You do have to handle both the up and down events for a key, as WE requires
that you return the same value to tell it what should be done in both cases.
Another time I have used the application object onCursorKey event, because
sometimes I did not want WE to speak (regardless of which of the cursor keys
was pressed), and sometimes I did want to let it speak, and I had to decide
after the key was pressed.
If you don't want to control how WE handles the key, instead of using the
onKeyDown and onKeyUp events, use the onKeyProcessedDown and
onKeyProcessedUp events. This keeps you from accidentally stopping WE from
handling a key, WE will respond faster, but you can still do what you need
to when the key you are interested in is pressed.
I think this is covered in class 17 of the scripting classes.
Hth,
Chip
-----Original Message-----
From: Scripting
[mailto:[email protected]] On
Behalf Of David via Scripting
Sent: Saturday, March 28, 2015 9:30 AM
To: GWScripting
Subject: Acting on certain keystrokes
For the illustrative purpose, let's say I need my app to act upon
certain keystrokes, for instance silencing speech output whenever the
defined keys are being pressed. Could anyone with experience, please,
point me in some direction, or even provide a few lines of sample coding?
I have been reading a bit in the Reference manual, but am afraid it did
not make too much sense to me, for whatever reason. Pretty sure, first I
get the grasp of it, this might be a somehow trivial matter of coding,
but that is just not kicking in today. Smiles.
OK, so let's say, I want to silence the speech, with the SILENCE
command. This should be done, whenever the user hits the CTRL-key, or
the Down-Arrow key. No other keystrokes. Well, remember this is the
definitions for illustrative purposes, so the end app might have more
sofisticated sets of keys, but I just wanted some samples to show the
difference in operating with different kinds of keystrokes.
OK, I do know of the Silence command, and my guess is, that I somehow
need to hook onto the KeyUp or KeyDown events. Or, is there any other
events or commands needed for this kind of process. In case this is what
I need, which of the two aforementioned events should I preferably be
hooking onto, and what might be some of the pitfalls to look out for and
error causioning? Also, what would be the more exact command line to
hook onto the event. Can I for instance send one command, holding a set
of specific keys, (like the Ctrl-key on its own, or, alternatively the
Down-Arrow key on its own), or will I have to deal with this in two
separate command lines? And, Is it at all possible to hook on to a
modifier keystroke on its own, like the ctrl without any other keys
pressed - or, will the interface only accept a fully qualified keystroke
like Ctrl-A?
Any ideas, feedback and experiences in this landscape, will be greatly
appreciated. Thanks,
--
David
_______________________________________________
Any views or opinions presented in this email are solely those of the author
and do not necessarily represent those of Ai Squared.
For membership options, visit
http://lists.window-eyes.com/options.cgi/scripting-window-eyes.com/lists3717
%40comcast.net.
For subscription options, visit
http://lists.window-eyes.com/listinfo.cgi/scripting-window-eyes.com
List archives can be found at
http://lists.window-eyes.com/private.cgi/scripting-window-eyes.com
_______________________________________________
Any views or opinions presented in this email are solely those of the author
and do not necessarily represent those of Ai Squared.
For membership options, visit
http://lists.window-eyes.com/options.cgi/scripting-window-eyes.com/archive%40mail-archive.com.
For subscription options, visit
http://lists.window-eyes.com/listinfo.cgi/scripting-window-eyes.com
List archives can be found at
http://lists.window-eyes.com/private.cgi/scripting-window-eyes.com