| View previous topic :: View next topic |
| Author |
Message |
Jim Boisclair Guest
|
Posted: Mon Jun 28, 2004 12:12 am Post subject: trapping the tab key |
|
|
How does one trap a tab key event in a TEdit?
TIA JBB
|
|
| Back to top |
|
 |
Dirk Schnitzler Guest
|
Posted: Mon Jun 28, 2004 6:59 am Post subject: Re: trapping the tab key |
|
|
Hi Jim.
If you don´t care about the mouse, try using
"OnExit" instead of "OnKeyPress" (I guess you´re
using now).
Greetz, Dirk.
--
dschnitzler at ac-magnetic dot de
"Jim Boisclair" <bois (AT) ix (DOT) netcom.com> schrieb im Newsbeitrag
news:40df62e4 (AT) newsgroups (DOT) borland.com...
| Quote: | How does one trap a tab key event in a TEdit?
TIA JBB
|
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Mon Jun 28, 2004 7:56 am Post subject: Re: trapping the tab key |
|
|
Jim Boisclair <bois (AT) ix (DOT) netcom.com> wrote:
| Quote: | How does one trap a tab key event in a TEdit?
|
You can't because VK_TAB never reaches the edit. The only
reliable way that I've been able to do what you want is to
intercept the keypress at the application level using the
Application's OnMessage event:
//--- in the main form's header -------------------------------
private: // User declarations
void __fastcall AppMessage( TMsg &Msg, bool &Handled );
//--- in the main form ----------------------------------------
__fastcall TMain::TMain(TComponent* Owner) : TForm(Owner)
{
Application->OnMessage = AppMessage;
}
//-------------------------------------------------------------
void __fastcall TMain::AppMessage( TMsg &Msg, bool &Handled )
{
if( Msg.message == WM_KEYDOWN || Msg.message == WM_KEYUP )
{
if( Msg.wParam == VK_TAB )
{
if( Msg.message == WM_KEYDOWN )
{
if( (GetKeyState(VK_SHIFT) & 0x80) == 0x80 )
{
// it's a back tab
}
}
// set the key to nothing
Msg.wParam = 0;
}
}
}
//-------------------------------------------------------------
You can determine the control that has focus using the
TScreen's ActiveControl property:
if( Screen->ActiveControl == Form2->Edit1 )
{
//
}
or
if( dynamic_cast<TEdit*>(Screen->ActiveControl) )
{
// it's a TEdit that has focus
}
~ JD
|
|
| Back to top |
|
 |
Corey Murtagh Guest
|
Posted: Mon Jun 28, 2004 10:01 am Post subject: Re: trapping the tab key |
|
|
JD wrote:
| Quote: | Jim Boisclair <bois (AT) ix (DOT) netcom.com> wrote:
How does one trap a tab key event in a TEdit?
You can't because VK_TAB never reaches the edit. The only
reliable way that I've been able to do what you want is to
intercept the keypress at the application level using the
Application's OnMessage event:
|
Another method that works for me (on BCB4, still) is binding Tab to an
action. This is useful if you have a small number of controls that you
want special Tab key processing for, since you can conditionally enable
the action. It also saves messing around with key messages to figure
out which key combo is being pressed... so you don't have to implicitly
check for Ctrl-Tab and Shift-Tab.
--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur!"
|
|
| Back to top |
|
 |
Jim Boisclair Guest
|
Posted: Mon Jun 28, 2004 5:56 pm Post subject: Re: trapping the tab key |
|
|
Acually, I've used everything I can think of; Keyup, down, onchange,on
exit and nada for a response from any of them. I'm BCB5 btw. But
thanks for your help.
JBB
|
|
| Back to top |
|
 |
Jim Boisclair Guest
|
Posted: Mon Jun 28, 2004 6:04 pm Post subject: Re: trapping the tab key |
|
|
OK, as I was telling Dirk, I can't get any of the usual suspects to
respond so I'm goin with you. Thanks. JBB
|
|
| Back to top |
|
 |
|