DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: vs2008 express vc++ has anyone gotten RegisterHotKey to use mouse?  (Read 6,934 times)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
I know AutoIt3 is written in C++ and it doesn't accommodate mouse hotkeys the way ahk does. I'm wondering if the reason is that vc++ RegisterHotKey doesn't, if you use any mouse virtual keys. At least I couldn't get one to work with an hour of effort.  The keyboard keys work fine with WinKey or Alt or whatever.  But any mouse key, VK_LBUTTON or whatever, even if the RegisterHotKey call succeeds, press the hotkey and you get nadda.

Is there a secret or is it just broken?

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,652
    • Cody Award
    • Participated in NANY Challenge Five Times
Re: vs2008 express vc++ has anyone gotten RegisterHotKey to use mouse?
« Reply #1 on: September 11, 2010, 03:34 PM »
Not sure exactly what you're after - Do you want/need to have a global system lever hot key registered? Or do you just want an application to look for/respond to A + B?

If it's application level you can use the below (snipped from an office project) in the message loop to get/capture/respond to keyboard or mouse events - combining them should be fairly straight forward.
Code: (cpp)
                                          //-------------------------------------+++--> END of Case WM_SYSCOMMAND
//==================================================================================
	case WM_NOTIFY: {
		LPNMLISTVIEW pnm = (LPNMLISTVIEW)lParam;
		//------------------------------------------------------------------------------+++-->
		if(((LPNMHDR)lParam)->code == LVN_KEYDOWN) { //======== Capture Key Strokes Here.  <<<
			hListView = GetWindow(hWnd, GW_CHILD); //-> ListView Child Control Handle
			LPNMLVKEYDOWN nmkey = (LPNMLVKEYDOWN)lParam;
			switch(nmkey->wVKey) {
			  case VK_RETURN:
				if((int)SendMessage(hListView, LVM_GETNEXTITEM, -1, LVNI_SELECTED) != -1) {
					GetPartsOrderDetails(hListView, FALSE);  // Open Selected Order(s)
				 }else{ //----------------------------------//--+++-->
					GetPartsOrderDetails(hListView, TRUE); // Give User Error Message
				} break;
			}
		}
		//------------------------------------------------------------------------------+++-->
		if(((LPNMHDR)lParam)->code == NM_DBLCLK) { //========= Capture Mouse Clicks Here.  <<<
				HWND hListView = GetWindow(hWnd, GW_CHILD); //-> ListView Child Control Handle

			if((int)SendMessage(hListView, LVM_GETNEXTITEM, -1, LVNI_SELECTED) != -1) {
				GetPartsOrderDetails(hListView, FALSE);  // Open Selected Order(s)
			 }else{ //----------------------------------//--+++-->
				GetPartsOrderDetails(hListView, TRUE); // Give User Error Message
			}
		 }
	} //------------------------------------------------+++--> END of Case WM_NOTIFY
//==================================================================================

Sorry I couldn't find a combo'ed example - I know I've done it somewhere - So it can't be too hard.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Re: vs2008 express vc++ has anyone gotten RegisterHotKey to use mouse?
« Reply #2 on: September 11, 2010, 09:42 PM »
Since RegisterHotKey has VK keys for mouse buttons I thought I'd try them.  Even if they register without error, nothing happens when you click in combination with a modifier key.

I suspect it's dead otherwise it would be simple for AutoIt3 to use global mouse hotkeys. I know it's done in c++. That leads me to suspect the facility is either totally broken or convoluted enough to be unusable.

So again it looks like if you want global mouse hotkeys ahk is the choice. :)
I'd prefer coding with something with more scoping structure.. but it's tough to beat it for ease of mouse hotkey creation.

Just thought I'd post in case someone has done it.  But, if it was easy the AU3 guys would probably have done it already. :)


Original address: https://www.donationcoder.com/forum/index.php?topic=23951.0