🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages Started by Russell Allen Mon, 25 Sep 2006 14:31
Cancelling Esc key being pressed
#3072
Author: Russell Allen
Date: Mon, 25 Sep 2006 14:31
25 lines
1717 bytes
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
#3073
Author: Remy Lebeau (TeamB)
Date: Mon, 25 Sep 2006 17:32
33 lines
1870 bytes
"Russell Allen" <russell.allen@bt.com> wrote in message
news:4517e850$1@newsgroups.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
Re: Cancelling Esc key being pressed
#3076
Author: 4N
Date: Tue, 26 Sep 2006 17:14
49 lines
2545 bytes
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@no.spam.com> ha scritto nel messaggio 
news:45181312$1@newsgroups.borland.com...
>
> "Russell Allen" <russell.allen@bt.com> wrote in message
> news:4517e850$1@newsgroups.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
>
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads