Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » RegisterSystemHotKey() only inside a program
RegisterSystemHotKey() only inside a program [message #36086] Thu, 26 April 2012 11:36 Go to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello all

RegisterSystemHotKey() permits to call a function when pushing a key while the program is running.

The problem is that this is system wide so, if the program has got for example the F5, Firefox will not update using F5.

Do you know if there is some similar function but valid only if your program window is on top?


Best regards
Iñaki

[Updated on: Thu, 26 April 2012 11:37]

Report message to a moderator

Re: RegisterSystemHotKey() only inside a program [message #36087 is a reply to message #36086] Thu, 26 April 2012 15:20 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Hi koldo:

Interesting question. I don't have an answer but you should be able to find it easily. I assume there is a mechanism in EventLoop or similar things to dispatch keyboard event to appropriate Ctrls, you may examine code in that part to see if an opportunity has been offered (eg, by way of Callback) to library user to intercept the keyboard event. If not, you can do a little hack there Smile

Re: RegisterSystemHotKey() only inside a program [message #36088 is a reply to message #36087] Thu, 26 April 2012 15:40 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Hi koldo:

I examined some relevant upp source, chance is there is no such facilities provided currently.

eg, for Win32

$(uppsrc)/CtrlCore/Win32Wnd.cpp
void Ctrl::sProcessMSG(MSG& msg)
{
	if (msg.message == WM_HOTKEY) {
		if(msg.wParam >= 0 && (int)msg.wParam < Ctrl::hotkey.GetCount())
			Ctrl::hotkey[(int)msg.wParam]();
		return;
	}
	if(msg.message != WM_SYSKEYDOWN && msg.message != WM_SYSKEYUP
	|| PassWindowsKey((dword)msg.wParam) || msg.wParam == VK_MENU) //17.11 Mirek - fix to get windows menu invoked on Alt+Space
		TranslateMessage(&msg); // 04/09/07: TRC fix to make barcode reader going better

        // Code can be inserted here to add the required facility IMHO

	if(IsWindowUnicode(msg.hwnd))
		DispatchMessageW(&msg);
	else
		DispatchMessage(&msg);
}
Re: RegisterSystemHotKey() only inside a program [message #36091 is a reply to message #36086] Thu, 26 April 2012 15:53 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Koldo,

Why so complicated? I think that the functionality you want can be achieved simply by overriding Key() method in your main class, am I right? If the focused Ctrl doesn't accept the key, the event "bubbles" up the ctrl tree, until it reaches the main class, which would handle it the way you want.

Are we talking about GUI app? Or is there something I'm missing?

Best regards,
Honza
Re: RegisterSystemHotKey() only inside a program [message #36092 is a reply to message #36091] Thu, 26 April 2012 16:27 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Thank you Honza

It is as simple as that.

Thank you too Lance Smile .


Best regards
Iñaki
Re: RegisterSystemHotKey() only inside a program [message #36093 is a reply to message #36092] Thu, 26 April 2012 19:19 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Simple, smart and it should work in most situations and in particular it works in your situation.
Re: RegisterSystemHotKey() only inside a program [message #36098 is a reply to message #36091] Fri, 27 April 2012 09:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
dolik.rce wrote on Thu, 26 April 2012 09:53

Hi Koldo,

Why so complicated? I think that the functionality you want can be achieved simply by overriding Key() method in your main class, am I right? If the focused Ctrl doesn't accept the key, the event "bubbles" up the ctrl tree, until it reaches the main class, which would handle it the way you want.

Are we talking about GUI app? Or is there something I'm missing?

Best regards,
Honza



That is true and obvious, but there is one more usage scenario not covered (or not easily): this works only for single top-level window.

Anyway, you can also InstallKeyHook, which is application-wide.
Re: RegisterSystemHotKey() only inside a program [message #36103 is a reply to message #36098] Fri, 27 April 2012 12:43 Go to previous message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Very interesting. And there are:
- MouseHook
- KeyHook
- StateHook


Best regards
Iñaki
Previous Topic: Problem compiling r4596
Next Topic: PushButton with text in the bottom
Goto Forum:
  


Current Time: Fri Apr 19 04:01:58 CEST 2024

Total time taken to generate the page: 0.04541 seconds