LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to simulate an event

I try to simulate an EVENT_KEYPRESS programatically.
The FakeKeystroke function only sends the event to the panel (and to the control that calls it).
Is there a way to simulate an event for a control?
Thanks
0 Kudos
Message 1 of 6
(3,962 Views)
One possible way, asuming that you are using callbacks is to force a callback, by calling the callback function, and filling in the variables for the control that you want to simulate.
i.e. if you have a dummy control, when it is pressed, in it's serviceing code, include a call to the callback that services the control that you wish to simulate. Instead of the user interface passing the values for the panel, control etc in the call back function call... 'hardwire' the values for a particular control in there instead. Of course you would need to either check the UIR header file, or run the program with a breakpoint in the callback function to obtain the correct values first...
It's not particularly elegant, but if you are just wanting to simulate a control during deb
ug, it's an easy way
Message 2 of 6
(3,962 Views)
I cannot call the callback function of the control (it is inside an instrument), that's why I try to generate an event.
0 Kudos
Message 4 of 6
(3,962 Views)
Sorry that I still don't understand exactly what you are trying to do. I don't know what you mean by the callback function is in the instrument. Maybe a Panel Callback function catching a keypress would help. If not give me a little more detail about your application.

Grant
Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 5 of 6
(3,962 Views)
You are right, it needs more details.
I am using the Password control of LabWindows (delivered as an instrument). I developed a num keyboard for a touchscreen. I am trying to transform the clic on a button into a key press for the password control (in order to use all the facilities of this tool).
The password control and the "numeric buttons" are into a panel. I tried first to use the FakeKeystroke function but this event is transmitted to the button that calls the function and the panel but not to the password control.
Actually, the only solution I have is to add a character into the string of the password control. But I have to re-develop some features (control of length, backspace key, first entry...).
Thanks for your help.
0 Kudos
Message 6 of 6
(3,962 Views)
To use your callback functions just do something like this:

CallbackFunctionName(99,99,EVENT_NAME,0,0,0);

This executes the code handling the event called EVENT_NAME in the callback function.

If you get tired of typing all that try some handy #defines.


#define EC (99,99,EVENT_COMMIT,0,0,0)
#define KP (99,99,EVENT_KEYPRESS,0,0,0)

FunctionName(EC);

//## To fake a keystroke
FunctionName(KP);

int CVICALLBACK FunctionName(int panel, int control, int event, void *callBackData, int eventdata1, int eventdata2)
{
switch(event)
{
case EVENT_COMMIT:
MessagePopup("Running EVENT_COMMIT","");
break;
case EVENT_KEYPRESS:
MessagePopup("Runnying EVENT_KEYPRESS","");
break;
}

If you are in to using more then 98 panels and/or controls ju
st use bigger numbers like 999 instead.
Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 3 of 6
(3,962 Views)