Fix Bug w/re to Keyboard Events in MouseBoxConsider 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?
What is the improvement you would like to see?
Why is this idea important?
Automation and ScriptingRe: Fix Bug w/re to Keyboard Events in MouseBoxWow, 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:

Re: Fix Bug w/re to Keyboard Events in MouseBoxI 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:

Re: Fix Bug w/re to Keyboard Events in MouseBoxI 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:

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

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;
Re: Fix Bug w/re to Keyboard Events in MouseBox - Status changed to: AcknowledgedHi @ErraticAttack, and everyone who has commented. This sounds like a bug. We're sharing with our technical support.
Re: Fix Bug w/re to Keyboard Events in MouseBoxUnfortunately 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;Re: Fix Bug w/re to Keyboard Events in MouseBoxThanks @_jr, this makes total sense -- just like Qt events.
Re: Fix Bug w/re to Keyboard Events in MouseBox - Status changed to: Delivered