08-30-2011 11:57 AM
In my LCVI 2009 app, the space bar and the Enter key both cause a commit event to be sent to whichever panel button has focus. I want this behavior for the Enter key, but NOT the space bar.
I have 45-50 panels with tens of buttons on each panel. So I'd like a "One Call Blanket Fix" if possible, rather than having to take some action for each panel (or worse - for each button on each panel).
Is there anything I can do?
Thanks
Solved! Go to Solution.
08-30-2011 01:43 PM
You can prevent this behavior by trapping and swallowing the keypress event. Normally, this would be done in the callback for the specific control for which you want to prevent the behavior. But since you want to do it for all buttons in all panels, and you don't want to create/modify all those callback functions, your best bet is to define a main callback for your application so that you can catch all keypress events that occur throughout your GUI. This is and example of how you could do it:
InstallMainCallback (mainCB, NULL, 0);
...
int CVICALLBACK mainCB (int panelOrMenuBarHandle, int controlOrMenuItemID, int event, void *callbackData, int eventData1, int eventData2)
{
intkey, style;
if (panelOrMenuBarHandle > 0 && controlOrMenuItemID > 0)
{
if (event == EVENT_KEYPRESS)
{
GetCtrlAttribute (panelOrMenuBarHandle, controlOrMenuItemID, ATTR_CTRL_STYLE, &style);
if (style == CTRL_SQUARE_COMMAND_BUTTON_LS)
{
key = GetKeyPressEventCharacter (eventData2);
if (key == ' ')
return 1;
}
}
}
return 0;
}