11-14-2008 04:07 PM
Hi all!
I have a quite tricky question...
I would like to insert an "easter egg" in my Labwindows program.. something like a popup message or a panel that appear only if the user press a given key combination..
Any suggestion on how to implement such a feature?
Thank you for the help.. I know that it is not a vital thing..
Francesco
11-15-2008 06:32 AM
Well, I can think at at least two ways of doing that.
1. You can install a callback on the main panel trapping EVENT_KEYPRESS event: on the event callback, discriminate which key has been pressed and operate on the correct key combination
2. Create a button, place it outside the visible region of your mainpanel and associate it the desired key combination: in the button callback show your popup panel
11-16-2008 04:53 AM
Hi Roberto!
thank you for your hints..
regarding solution #1, how can I install a callback without a control??
However, I also tried to place a button, configure it as "non visible" and the associate to it a shortkey configuration.. but it did not work 😞
Ciao
Francesco
11-16-2008 01:27 PM - edited 11-16-2008 01:29 PM
Besides control callbacks, you install a callback on a panel either in the UIR editor or programmatically by calling InstallPanelCallback. The panel callback responds to a subset of the user events among which EVENT_KEYPRESS can be found.
Regarding the second solution, if a control is not visible is not operable at all, neither with the mouse nor with the keyboard. I suggested you to move it outside the visible region of the panel exactly to "hide" it to the user while keeping it still "visible" (and so fully operable).
Ciao!
BTW It seems you are italian like me: are you aware of the italian forum board?
11-17-2008 01:09 AM - edited 11-17-2008 01:11 AM
Hi Francesco,
For your application, I feel that it is not a must to use InstallPanelCallback.
As mentioned in the function help, it is actually identical to specifying a panel callback within the UIR (by double-clicking the panel and filling in the callback field).
But as an advantage, by using InstallPanelCallback you can change which function will be serving the panel events while the application is running.
To do this, you should first uninstall the current callback by calling InstallPanelCallback with the function parameter set to NULL and then call it again with the new callback function name.
You can even add multiple callbacks to a panel using ChainPanelCallback function. So for any event on the panel multiple function blocks "get activated".
So, you have lots of flexibility 🙂
11-17-2008 03:10 AM
11-19-2008 12:31 PM
Hi All!
I would like to use the InstallPanelCallback but it is not clear to me how to use this command.
Could someone provide a simple example of it usage?
I would like only that a MEssagePopUp appear when someone strikes a combination of keys, let's say shift+A or ABC.
Thanks for any help...
Francesco
11-19-2008 03:13 PM - edited 11-19-2008 03:14 PM
This is a sample callback that prompts a message on Ctrl + A key combination:
/****************************************************************************/
int CVICALLBACK mainCbk (int panel, int event, void *callbackData,
int eventData1, int eventData2)
// Callback installed on main panel
{
int virtualKey, modifierKey, asciiKey, tmpH, error = 0;
char msg[256];
switch (event) {
case EVENT_KEYPRESS:
// eventData1: a 4-byte integer consisting of 3 fields: 0x00MMVVAA
// MM = the modifier key, VV = the virtual key, AA = the ASCII key
// key masks are defined in "userint.h"
virtualKey = eventData1 & VAL_VKEY_MASK;
modifierKey = eventData1 & VAL_MODIFIER_KEY_MASK;
asciiKey = eventData1 & VAL_ASCII_KEY_MASK;
// Ctrl + A: Prompt a message
if (modifierKey == VAL_MENUKEY_MODIFIER && asciiKey == 'A') {
MessagePopup ("Key Press", "Message.");
}
break;
}
Error:
if (error < 0) {
sprintf (msg, "Error %d received in mainCbk.", error);
MessagePopup ("Severe error", msg);
}
return 0;
}
Here the line to install this callback on the main panel:
InstallPanelCallback (panelHandle, mainCbk, 0);
Remember that the panel callback can be set in the UIR editor without need to use InstallPanelCallback.
11-20-2008 01:50 AM
Thank you very much Roberto..
you really know a lot 😉
Ciao
Francesco
11-20-2008 07:22 AM
Hi Roberto,
as far as I understand, I cannot use a combination like SHIFT+CTRL+A since both SHIFT and CTRL are defined as "key modifiers".
Am I right?
Francesco