Hi Marty,

    You can not pass a constant into the list, which is what you are doing. 
For you force it to remain as is. So, declare the True as a variable also, 
then you will get it to work.

    In other words, p3 = True then place p3 as the replacement for True in 
the statement...
        Bruce

Sent: Saturday, December 22, 2012 11:35 PM
Subject: RE: help with JScript example


Hi Chip,
Sorry, JScript does not except the ",,, true) "comma construct for passing 
empty parameters. If I attempt to pass parameters in this way I will get a 
syntax error at column 85. This is because to declare an empty parameter you 
have to first make it known to the JScript interpreter and give it no value 
like so:
var Parm1, parm2;
Using square brackets in the line:
var MyHotkey = Keyboard.RegisterHotKey("Control-Shift-Windows-h", 
"SpeakHelloWorld", [p1, p2], true);
Should be passing p1 and p2 as empty parameters as an array, to the call 
back proc which is the way you should pass optional arguments s in JScript. 
The docs state that the last parameter of a function can be an array to pass 
optional arguments, or you can use an array to pass a a single list of 
optional parameters.
I have tried to pass true as a parameter, by using the true literal to set 
p3 like so:
var p1, p2;
var p3 = true;
var MyHotkey = Keyboard.RegisterHotKey("Control-Shift-Windows-h", 
"SpeakHelloWorld", [p1, p2,

p3]);
this fails to with the error:
"Line 4 Column 1 The specified function does not have the proper number or 
types of parameters. <  0x8004E001 >". Line 4 is the hotkey declaration 
shown above.
When the code is written as in my first example like so:
// Detect if a key has been pressed twice in succession
var p1, p2;
var MyHotkey = Keyboard.RegisterHotKey("Control-Shift-Windows-h", 
"SpeakHelloWorld", [p1, p2],

true);
 function SpeakHelloWorld(firstPress)
{
Speak(firstPress);
       if (!firstPress) {
                   Speak("Key pressed twice in succession");
}
}
the script fails, by failure I mean I am not getting any errors, the script 
runs, but does not behave as expected. The first press parameter is not 
being set to false which is happening in the VBScript example, the first 
press parameter remains stubbornly set at true. The only other thing of 
interest about this script is the use of the exclamation mark used in 
JScript as the Not operator like so:
       if (!firstPress) {
                   Speak("Key pressed twice in succession");
}
I can and have easily test that this is working by setting the true value to 
false in the hotkey declaration, and this element of the script is working 
fine, in other words the first press parameter when set to false in the 
hotkey declaration remains stubbornly set to false, and I hear the message 
"key pressed twice in succession". I don't know what to test and try next 
really. Hope some body can hhelp.
Warm regards.
Martin Webster.
I.T. Director for Kirklees Visual Impairment Network.




--- On Sat, 12/22/12, Chip Orange <[email protected]> wrote:

> From: Chip Orange <[email protected]>
> Subject: RE: help with JScript example
> To: [email protected]
> Date: Saturday, December 22, 2012, 9:01 PM
> Hi Martin,
>
> While I don't know Jscript at all, I suspect the problem is
> your use of p1
> and p2 when calling the RegisterHotKey method. I don't
> know what the
> significance of the brackets is, but in this case you don't
> want any
> parameters passed in the third and forth places at all (just
> add commas
> enough so you will end up with 5 parameters if that's
> allowed in Jscript).
> Passing parameters of any type in the third and forth places
> will cause
> filtering to occur, and cause a second parameter to be
> necessary for your
> routine which is to be called (which for some reason GW
> makes be the first
> parameter in your called routine).
>
> So, I think your statement should look like:
>
> var MyHotkey =
> Keyboard.RegisterHotKey("Control-Shift-Windows-h",
>  "SpeakHelloWorld",,, true)
>
> Hth,
>
> Chip
>
> -----Original Message-----
> > From: martin webster [mailto:[email protected]]
> > Sent: Saturday, December 22, 2012 8:16 AM
> > To: [email protected]
> > Subject: help with JScript example
> >
> > Hi all,
> > I cannot get the following example to work using
> JScript. Can somebody
> > help please.
> > // Detect if a key has been pressed twice in
> succession
> > var p1, p2;
> > var MyHotkey =
> Keyboard.RegisterHotKey("Control-Shift-Windows-h",
> > "SpeakHelloWorld", [p1, p2], true)
> > function SpeakHelloWorld(firstPress)
> > {
> > Speak(firstPress);
> > if (!firstPress) {
> >
> Speak("Key pressed twice in succession");
> > }
> > }
> > Warm regards.
> > Martin Webster.
> > I.T. Director for Kirklees Visual Impairment Network.
>
>

Reply via email to