Key focus stays on toolbar when input focus is shifted

Key focus stays on toolbar when input focus is shifted

Post by Chris Nybe » Tue, 19 Aug 2003 18:37:39


I have a toolbar with toolbuttons that drop downs a popup menu, the toolbar
works like a regular main menu on a form. If a use the alt key and select
something from the menu that opens a new window and then sets input focus to
the new window, I can't input anything because the key focus is still on the
toolbuttons. It stays like this until I press the alt key twice.

Does anyone know a solution to this problem? I'm using C++Builder5. Thanks
for your help!

/Chris
 
 
 

Key focus stays on toolbar when input focus is shifted

Post by JD » Tue, 19 Aug 2003 18:44:41


I'm unaware of any problems like this with ToolButtons. What
does the code look like?

~ JD

 
 
 

Key focus stays on toolbar when input focus is shifted

Post by Chris Nybe » Tue, 19 Aug 2003 19:09:26

It works perfectly if I use the mouse to select the menu item, but when
using the keyboard (hotkeys) it doesn't. There is no specific code, all I do
is using the OnClick event and create a new form and show it with the
ShowModal method.

/Chris
 
 
 

Key focus stays on toolbar when input focus is shifted

Post by JD » Tue, 19 Aug 2003 19:46:31


I was unable to reproduce your problem. How are you setting /
using the hotkeys?

~ JD
 
 
 

Key focus stays on toolbar when input focus is shifted

Post by Chris Nybe » Tue, 19 Aug 2003 20:52:36

To the toolbutton captions I have added & to indicate the hotkey. On the new
form I have an edit that gets the input focus, the cursor gets there but the
key notifications still go to the toolbutton menu on the main form!

/Chris



toolbar
to
the
 
 
 

Key focus stays on toolbar when input focus is shifted

Post by JD » Tue, 19 Aug 2003 21:25:47


That's not a hotkey. It's an accellerator key - a distinction
worth noting.


Again I was unable to duplicate this problem. I set the caption
and added a popup menu to the Toolbuttons' DropDownMenu property.

In the popup menu I set the OnClick to a single line:

Form2->ShowModal();

It worked using Alt to dropdown the menu and Alt or arrow/enter
keys to initiate the menu item OnClick.

Could there be something in the Form2 OnShow or OnActivate that's
causing the problem?

~ JD
 
 
 

Key focus stays on toolbar when input focus is shifted

Post by Chris Nybe » Tue, 19 Aug 2003 21:48:23

Sorry for getting hotkeys and accelerator keys mixed up. It works well when
using shortcuts. I have the same setup on my application as you do: One form
containing a toolbar with one toolbutton that has a popup on the
DropDownMenu property.
The OnClick event shows a second form with two edits. The first edit control
gets focused, but when I press a key (for example 'A'), the A won't show up
in the edit, but I can use arrows to navigate around in the toolbutton menu
and open new windows (even though I used the ShowModal method!). I've tried
several new test applications and it is the same in all of them. When I
press the ALT key twice (which generates two WM_SYSKEYUP messages), the
toolbutton menu loses focus and I can write in the Edit boxes on the second
form.

Are you using C++Builder5 with Update Pack 1?

Chris
 
 
 

Key focus stays on toolbar when input focus is shifted

Post by JD » Tue, 19 Aug 2003 23:24:56


I use BCB6 - sorry - but I searched a list of known problems
with v5 and there was no mention of this AND no mention about
it being fixed for v6 but that only means that I couldn't find
anything documented.

One thing that you can try is to add an OnShow event to Form2:

void __fastcall TForm2::FormShow(TObject *Sender)
{
keybd_event( VK_MENU, 0, 0, 0 );
keybd_event( VK_MENU, 0, KEYEVENTF_KEYUP, 0 );
keybd_event( VK_MENU, 0, 0, 0 );
keybd_event( VK_MENU, 0, KEYEVENTF_KEYUP, 0 );
}

~ JD
 
 
 

Key focus stays on toolbar when input focus is shifted

Post by Chris Nybe » Wed, 20 Aug 2003 05:07:42

The code you suggested did work!
Isn't it strange that this problem is not known? Menus from a toolbar should
be used in a lot of applications. I'm thankful for your help!

/Chris

"JD" < XXXX@XXXXX.COM > skrev i meddelandet