How to have shortcut to command which is on some button Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
james.chengguangwang
Knows some wx things
Knows some wx things
Posts: 38
Joined: Wed Aug 02, 2006 4:59 am

How to have shortcut to command which is on some button

Post by james.chengguangwang » Tue Sep 05, 2006 3:33 am

Hi All,

I would like to have shortcut to command which is on some button. Is it possible? and how to implement it? thanks!

regards
James

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Re: How to have shortcut to command which is on some button

Post by upCASE » Tue Sep 05, 2006 6:46 am

Hi!
james.chengguangwang wrote:I would like to have shortcut to command which is on some button. Is it possible? and how to implement it?
Maybe wxWindow::RegisterHotKey() could help. Note that this would register a system wide hotkey, so your app would respond even if it isn't focused or active.
You might also try with wxKeyEvent.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

james.chengguangwang
Knows some wx things
Knows some wx things
Posts: 38
Joined: Wed Aug 02, 2006 4:59 am

Post by james.chengguangwang » Tue Sep 05, 2006 6:51 am

Hi upCASE,

I have found a method to implement it as follows:

Code: Select all

m_XXX = new wxButton(this, ID_OK_BUTTON, wxT("&OK"));
And when I press the O key, the OnOK function will be invoked, but I still have a question that I want to let the 'O' character be underlined, sorry for my poor english ability, how can I do it? I mean only the 'O' character is underlined, thanks in advance!

thanks
James[/code]

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Tue Sep 05, 2006 10:09 am

Hi!
You mean like a menu accelerator, right?
I'm not really sure about this, but when using something like "&OK" it should display an underlined "O". Maybe this is influenced somehow by system themes...
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

PhoenixPl
I live to help wx-kind
I live to help wx-kind
Posts: 179
Joined: Wed Feb 15, 2006 9:26 am

Post by PhoenixPl » Tue Sep 05, 2006 10:36 am

Try wxAcceleratorTable. It allows you to link almost any key combination. This example links Esc key with cancel button. Just put it in your window constructor.

Code: Select all

	m_button24 = new wxButton( this, ID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );

	wxAcceleratorEntry accel_entries[1];
	accel_entries[0].Set(wxACCEL_NORMAL,WXK_ESCAPE,ID_CANCEL);
	wxAcceleratorTable accel(1, accel_entries);
	SetAcceleratorTable(accel);

Post Reply