Board index » cppbuilder » Cancelling Esc key being pressed

Cancelling Esc key being pressed


2006-09-25 10:31:44 PM
cppbuilder56
Hi all,
I have a form with a FormKeyUp event handler intended to intercept the Esc key, and do something, as below (semi-pseudo-code).
TForm1::FormKeyUp(Sender, Key) {
if (Key == 27)
ShowMessage("Esc key pressed");
}
TForm1::Button1Click(Sender) {
MessageDlg("Proceed?", mtConfirmation, TMsgDlgButtons() <<
mbYes << mbCancel, 0);
// Can I put some code here to stop FormKeyUp firing when
// the user presses Esc?
}
The problem I'm having - when a piece of code elsewhere pops up a dialog box with a Cancel option, if the user presses "Esc" to cancel the dialog box, not only is the dialog box cancelled, the onkeyup event is being fired off as well!
Can I include a line to stop the Esc key press firing other events, or can I maybe unhook the OnKeyUp event handler before the dialog and rehook it after the dialog box?
Thanks in advance,
Russ
 
 

Re:Cancelling Esc key being pressed

"Russell Allen" < XXXX@XXXXX.COM >wrote in message
Quote
The problem I'm having - when a piece of code elsewhere pops up
a dialog box with a Cancel option, if the user presses "Esc" to cancel
the dialog box, not only is the dialog box cancelled, the onkeyup event
is being fired off as well!
void __fastcall TForm1::FormKeyUp(TObject *Sender, char &Key)
{
if( Key == VK_ESCAPE )
Key = 0;
}
Quote
Can I include a line to stop the Esc key press firing other events
No.
Quote
can I maybe unhook the OnKeyUp event handler before the dialog
and rehook it after the dialog box?
void __fastcall TForm1::Button1Click(TObject *Sender)
{
this->OnKeyUp = NULL;
MessageDlg("Proceed?", mtConfirmation, TMsgDlgButtons() << mbYes <<
mbCancel, 0);
this->OnKeyUp = FormKeyUp;
}
Gambit
 

Re:Cancelling Esc key being pressed

The problem is that OnActivate of a form isn't called when a form changes is
Focused status.
I tryed catching WM_ACTIVATE but the form is activated before it receives
the Escape message so you can't block esc when the form is not focused.
I was thinking to add a timer (which autodisables itself) of 300 ms that is
enabled when WM_ACTIVATE is catched and drop the Escape key in OnKeyUp()
function till the timer is active...
but I dunno if there's a better solution.
If you have a better idea let me know it :)
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >ha scritto nel messaggio
Quote

"Russell Allen" < XXXX@XXXXX.COM >wrote in message
news:4517e850$ XXXX@XXXXX.COM ...

>The problem I'm having - when a piece of code elsewhere pops up
>a dialog box with a Cancel option, if the user presses "Esc" to cancel
>the dialog box, not only is the dialog box cancelled, the onkeyup event
>is being fired off as well!

void __fastcall TForm1::FormKeyUp(TObject *Sender, char &Key)
{
if( Key == VK_ESCAPE )
Key = 0;
}


>Can I include a line to stop the Esc key press firing other events

No.

>can I maybe unhook the OnKeyUp event handler before the dialog
>and rehook it after the dialog box?

void __fastcall TForm1::Button1Click(TObject *Sender)
{
this->OnKeyUp = NULL;
MessageDlg("Proceed?", mtConfirmation, TMsgDlgButtons() << mbYes <<
mbCancel, 0);
this->OnKeyUp = FormKeyUp;
}


Gambit


 

{smallsort}