Hi,
I am looking for a way to emulate a button click when the user press a keyboard key (linked to the button by an accelarator table).
Any clue ?
Thanks.
Christophe Damour
How to emulate a button click ?
-
- Knows some wx things
- Posts: 39
- Joined: Thu Nov 25, 2004 10:10 am
- Location: Germany
My solution (which is already given is this);
= Jorgen
Code: Select all
wxMyApp::OnSomeButtonEvent(wxCommandEvent &event)
{
DoWhateverYouWant();
}
wxMyApp::DoWhateverYouWant()
{
}
// simply call DoWhateverYouWant directly, and do not fake the events, it is
// more clean this way, less code overhead also
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Thanks for your answers, I was not precise enough.
What I mean with "emulate button click" : when the user press the keyboard key, I would like the corresponding button in the dialog to behave like the key. That is to say button up when the key is up, button down when the key is down, button released when the key is released.
With the following lines, I handle the events correctly :
wxAcceleratorEntry entries[1];
entries[0].Set(wxACCEL_NORMAL, (int) 'A', ID_WXBTNA);
But I would like to synchronize the button and the key behaviour.
Christophe Damour
What I mean with "emulate button click" : when the user press the keyboard key, I would like the corresponding button in the dialog to behave like the key. That is to say button up when the key is up, button down when the key is down, button released when the key is released.
With the following lines, I handle the events correctly :
wxAcceleratorEntry entries[1];
entries[0].Set(wxACCEL_NORMAL, (int) 'A', ID_WXBTNA);
But I would like to synchronize the button and the key behaviour.
Christophe Damour
The only way is to emulate the mouse down / mouse up clicks I think when you are receiving a key up and key down event you want from the key .. but wht go through all this trouble I may ask ?
The problem is that your key is sent to the main frame I believe and not to the button. So you have to personally map all the keys to the buttons ..
I see no reason why you would not create a button with e.g. B&utton where the ALT-U becomes the accelerator.
Regards,
- Jorgen
The problem is that your key is sent to the main frame I believe and not to the button. So you have to personally map all the keys to the buttons ..
I see no reason why you would not create a button with e.g. B&utton where the ALT-U becomes the accelerator.
Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb