Board index » cppbuilder » How te get a KeyDown from a checkbox

How te get a KeyDown from a checkbox


2005-04-21 09:45:47 PM
cppbuilder113
Hi,
I have a checkBox but i can't get a keydown event from it. even not on my
form with keypreview turned on.
Is there a way to get that event or a work around
The key I have to catch are VK_DOWN and VK_UP.
The CheckBox is the only tabstop on a panel and on the VK_DOWN or VK_UP the
next panel should get the focus.
Regards,
jvdn
 
 

Re:How te get a KeyDown from a checkbox

Quote
I have a checkBox but i can't get a keydown event from it.
even not on my form with keypreview turned on.
Is there a way to get that event or a work around

The key I have to catch are VK_DOWN and VK_UP.

The CheckBox is the only tabstop on a panel and on the VK_DOWN
or VK_UP the next panel should get the focus.
I couldn't find an easier way than setting a keyboard hook.
Here's what I wrote. Please check it carefully and deeply, I
wrote it just to find a workaround to the behavior you reported
and I tested it for less than 30 seconds...
HHOOK KBHook;
LRESULT CALLBACK KeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{
if (code < 0) return(CallNextHookEx(KBHook, code, wParam,
lParam));
if (Form1->ActiveControl == Form1->CheckBox1)
{
if (((wParam == VK_DOWN) || (wParam == VK_UP)) &&
(!(lParam & 0x80000000)))
{
Form1->Perform(WM_NEXTDLGCTL, 0, 0);
return(1);
}
}
return(CallNextHookEx(KBHook, code, wParam, lParam));
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
KBHook = SetWindowsHookEx(WH_KEYBOARD,
(HOOKPROC)KeyboardProc, HInstance, 0);
}
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction
&Action)
{
UnhookWindowsHookEx(KBHook);
}
I hope it gives an idea at least, but maybe there are easier
solutions.
Steve.
 

Re:How te get a KeyDown from a checkbox

Steve
Thanks a lot for you sugestion,
I han't try it out because of the complexity
I have decided to use the easy way to remove all the panels and put all the
components on the same panel
create them all dynamicly.
I'm sorr yto respond so late.
jvdn
 

{smallsort}

Re:How te get a KeyDown from a checkbox

Quote
I han't try it out because of the complexity
Complexity? I practically posted the complete solution, it
should be checked a little, but it works...
Quote
I have decided to use the easy way to remove all the panels
and put all the components on the same panel
create them all dynamicly.
OK.
Steve.