 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Russell Allen Guest
|
Posted: Mon Sep 25, 2006 7:31 pm Post subject: Cancelling Esc key being pressed |
|
|
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 |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Sep 25, 2006 10:32 pm Post subject: Re: Cancelling Esc key being pressed |
|
|
"Russell Allen" <russell.allen (AT) bt (DOT) com> wrote in message
news:4517e850$1 (AT) newsgroups (DOT) borland.com...
| 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 |
|
| Back to top |
|
 |
4N Guest
|
Posted: Tue Sep 26, 2006 10:14 pm Post subject: 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)" <no.spam (AT) no (DOT) spam.com> ha scritto nel messaggio
news:45181312$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"Russell Allen" <russell.allen (AT) bt (DOT) com> wrote in message
news:4517e850$1 (AT) newsgroups (DOT) borland.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
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|