Guidance Forums / wxWidgets (wxWindows) in C++ / accelertor entry

Search 搜索
Home Home

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. accelertor entry
Posted by: 2004-01-03 11:29:24
hi, I have a user interface with some buttons and a textbox.
The buttons are supposed to be activated by pressing characters, but NOT when the textbox is selected. Then the characters should be entered in the textbox.

Also, this program plays back music, and the space bar is supposed to activate the play / stop function. but it should NOT activate the currently selected control.

Now i used accelerator entries for these chars and space, but this gives the problem:

-I cannot enter the chars used in the accelerator table in the text box.
-When space is pressed, not only will the program start or stop playing, the currently selected controll is also activated.

I know i could solve the first problem by using shft, ctrl or alt with the keys to activate the functions, but that is only a last resort, if possible without those, i want it without shift crtl and alt.

-Is there a way to not make controlls react to the space?

-Is there a way to bypass the accelerator table when the textbox is selected?

-Is there a key event in wxwindows so that i could make an event handler that is activated whenever a key is pressed. Then have the event handler check what controlls are selected, decide what shoult happen and call the appropriate function.
In the documentation i see only writen about mouse.event, not key event. Also if there is a possibility to do this, i would be very happy if you could give me some directions on how to do this. (how to pass the event to the textbox when the textbox is selected)

thanx in advance.
Message2. Re: accelertor entry
Posted by: KaReL 2004-01-03 15:05:37
I think it's pretty easy :)

You have to create your own class of each control you're using. Probably you're doing something like wxText * text = new wxText(this,-1) ... etc ...

This however will not be able to catch any events...

Now if you do this:

class MyTextControl : public wxText
// Do nothing (this means: take everything from above (in hierarchy: wxText) control


BEGIN_EVENT_TABLE(MyTextControl, wxText)
EVT_CHAR ( MyTextControl::On_KeyEvent )

it could be evt_char_hook or evt_key_down too...

In this event you should use StopPropagating or something like that, which means .... "I have handled the event, beat it now!"

Do the same for every button, where you check the char-key you want to activate the button with & the space bar...

There could be another way, but that's how I should do it ;)

Message3. Re: accelertor entry
Posted by: KaReL 2004-01-03 15:24:04
Check this out:

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
© Thu 2023-11-30  Guidance Laboratory Inc. Hits:0