cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
0 Kudos

Fix Bug w/re to Keyboard Events in MouseBox

Consider the below code:

Names Default To Here( 1 );
New Window( "SetKey Example", mb = MouseBox( tb = Text Box( "Press a key." ) ) );
mb << setkey( Function( {this, key}, show( key ) ) );
mb << setkeyenable( 1 );
mb << setfocus;

Pressing a button, such as K, causes the attached function to run twice.  Clearly one can produce a work-around with timing and such, but I think that even the JMP developers would consider such user-based work-arounds to be unfortunate.

 

What inspired this wish list request? 

(your template dropped my response to this question)

 

What is the improvement you would like to see? 

(your template dropped my response to this question)

 

Why is this idea important? 

(your template dropped my response to this question)

 

7 Comments
hogi
Level XII

Wow, what a cool functionality: setkey!

Thanks for mentioning ...

 

Nevertheless, really strange issue!
surprisingly, the function is not always triggered twice (see a,b,r,t,z) and for Return (and Enter), one gets an additional  End":

Jmp17 with german Keyboard:

hogi_2-1676633331848.png

 

 

hogi
Level XII

I wondered if it's due to pressing the key and relasing it again.
But  when you keep the key presses, the function is triggered again and again.

The result is particularly interesting when pressing return. Then it is:

 

hogi_0-1676717765633.png

 

hogi
Level XII

I wondered which time it takes between the two triggers of the command - and by doing so, I found an easy solution: 
just make the command slightly longer than show(key) - and it's just triggered 1x

 

The first function is triggerd twice:

hogi_1-1676726415349.png

 

uncommenting the second (slightly longer) function solves the problem:

 

hogi_0-1676726339517.png

 

Names Default To Here( 1 );
time0 = 0;

doSomething = Function( {this, key},
	time = HP Time();
	Write("\!n v1: ",key," ", time);
);

doSomething2 = Function( {this, key},
	time = HP Time();
	dt =  (time - time0)/1000000;
	Write ( "\!n v2: ", key," ", dt);
	time0 = time;
);


New Window( "SetKey Example",
	H List box(mb = MouseBox( tb = Text Box( "Press a key." )), Button Box ("save", onSave()))
);
mb << setkey( Function( {this, key}, doSomething( this, key ) ) );
//mb << setkey( Function( {this, key}, doSomething2( this, key ) ) );
mb << setkeyenable( 1 );
mb << setfocus;

mia_stephens
Staff
Status changed to: Acknowledged

Hi @ErraticAttack, and everyone who has commented. This sounds like a bug. We're sharing with our technical support. 

Jasean
Staff

Unfortunately the Mouse Box documentation is not quite complete.  We are aware, and it is on the list to be corrected.  In the meantime, please know that the << Set Key message is designed to respond to a "boolean" return value from the enclosed function.  If the function returns "true" (like 1), it indicates to Set Key that the key press was processed, and you will not get the apparent second function call.  If the function returns "false" (like 0), you get the behavior illustrated by the OP example.  Here is a modification of the OP example that writes a single statement to the log for each key press.

Names Default To Here( 1 );
New Window( "SetKey Example", mb = MouseBox( tb = Text Box( "Press a key." ) ) );
mb << setkey( Function( {this, key}, 
	show( key );
	1; // return "boolean" to indicate if the key press was processed.
) );
mb << setkeyenable( 1 );
mb << setfocus;
ErraticAttack
Level VI

Thanks @Jasean, this makes total sense -- just like Qt events.

mia_stephens
Staff
Status changed to: Delivered