[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32660] trunk/blender/intern/ghost/intern: Fix [#24337] Create vertex (and faces and edges) with "Control+LMB" doesn' t works!

Nathan Letwory nathan at letworyinteractive.com
Sat Oct 23 00:58:15 CEST 2010


Revision: 32660
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32660
Author:   jesterking
Date:     2010-10-23 00:58:12 +0200 (Sat, 23 Oct 2010)

Log Message:
-----------
Fix [#24337] Create vertex (and faces and edges) with "Control+LMB" doesn't works!
Reported by Lluc Roman?\195?\173 Bras?\195?\179

Some of my earlier changes to the modifier handling code accidently sent out new events for modifier keys when they where held down (repeat).

Also lay foundation for shift+numpad handling.

Modified Paths:
--------------
    trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp
    trunk/blender/intern/ghost/intern/GHOST_SystemWin32.h

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-10-22 22:31:40 UTC (rev 32659)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-10-22 22:58:12 UTC (rev 32660)
@@ -146,7 +146,6 @@
 	
 	// Check if current keyboard layout uses AltGr
 	this->keyboardAltGr();
-	
 	// Require COM for GHOST_DropTargetWin32 created in GHOST_WindowWin32.
 	OleInitialize(0);
 }
@@ -334,6 +333,11 @@
 GHOST_TSuccess GHOST_SystemWin32::init()
 {
 	GHOST_TSuccess success = GHOST_System::init();
+	
+	for(int i = 0; i < 255; i++) {
+		m_prevKeyStatus[i] = false;
+		m_curKeyStatus[i] = false;
+	}
 
 	/* Disable scaling on high DPI displays on Vista */
 	HMODULE user32 = ::LoadLibraryA("user32.dll");
@@ -375,25 +379,34 @@
 		if (::RegisterClass(&wc) == 0) {
 			success = GHOST_kFailure;
 		}
+		
+		// Add low-level keyboard hook for our process.
+		m_llKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, s_llKeyboardProc, wc.hInstance, 0);
 	}
+	
 	return success;
 }
 
 
 GHOST_TSuccess GHOST_SystemWin32::exit()
 {
+	// remove our low-level keyboard hook.
+	UnhookWindowsHookEx(m_llKeyboardHook);
+	
 	return GHOST_System::exit();
 }
 
 
 GHOST_TKey GHOST_SystemWin32::convertKey(GHOST_IWindow *window, WPARAM wParam, LPARAM lParam) const
 {
+	GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
 	bool isExtended = (lParam&(1<<24))?true:false;
 	
 	GHOST_TKey key;
 	GHOST_ModifierKeys oldModifiers, newModifiers;
-	((GHOST_SystemWin32*)getSystem())->retrieveModifierKeys(oldModifiers);
-	((GHOST_SystemWin32*)getSystem())->getModifierKeys(newModifiers);
+	system->retrieveModifierKeys(oldModifiers);
+	system->getModifierKeys(newModifiers);
+	
 
 	if ((wParam >= '0') && (wParam <= '9')) {
 		// VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39)
@@ -463,7 +476,12 @@
 				if(lchanged) {
 					key = GHOST_kKeyLeftShift;
 				} else {
-					key = GHOST_kKeyRightShift;
+					bool rchanged = oldModifiers.get(GHOST_kModifierKeyRightShift) != newModifiers.get(GHOST_kModifierKeyRightShift);
+					if(rchanged) {
+						key = GHOST_kKeyRightShift;
+					} else {
+						key = GHOST_kKeyUnknown;
+					}
 				}
 			}
 			break;
@@ -473,7 +491,12 @@
 				if(lchanged) {
 					key = GHOST_kKeyLeftControl;
 				} else {
-					key = GHOST_kKeyRightControl;
+					bool rchanged = oldModifiers.get(GHOST_kModifierKeyRightControl) != newModifiers.get(GHOST_kModifierKeyRightControl);
+					if(rchanged) {
+						key = GHOST_kKeyRightControl;
+					} else {
+						key = GHOST_kKeyUnknown;
+					}
 				}
 			}
 			break;
@@ -493,7 +516,12 @@
 				if(lchanged) {
 					key = GHOST_kKeyLeftAlt;
 				} else {
-					key = GHOST_kKeyRightAlt;
+					bool rchanged = oldModifiers.get(GHOST_kModifierKeyRightAlt) != newModifiers.get(GHOST_kModifierKeyRightAlt);
+					if(rchanged) {
+						key = GHOST_kKeyRightAlt;
+					} else {
+						key = GHOST_kKeyUnknown;
+					}
 				}
 			}
 			break;
@@ -635,6 +663,36 @@
 	minmax->ptMinTrackSize.y=240;
 }
 
+/* Note that this function gets *all* key events from the entire system (all
+ * threads running in this desktop session. So when getting event here, don't assume
+ * it's for Blender. Thus we only do status bookkeeping, so we can check
+ * in s_wndProc and processKeyEvent what the real keyboard status is.
+ * This is needed for proper handling of shift+numpad keys for instance.
+ */
+LRESULT CALLBACK GHOST_SystemWin32::s_llKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
+{
+	GHOST_SystemWin32* system = ((GHOST_SystemWin32*)getSystem());
+	KBDLLHOOKSTRUCT &keyb = *(PKBDLLHOOKSTRUCT)(lParam);
+	system->m_prevKeyStatus[keyb.vkCode] = system->m_curKeyStatus[keyb.vkCode];
+	if(keyb.flags) {
+		if((keyb.flags & LLKHF_EXTENDED) == LLKHF_EXTENDED) {
+		}
+		if((keyb.flags & LLKHF_ALTDOWN) == LLKHF_ALTDOWN) {
+		}
+		if((keyb.flags & LLKHF_UP) == LLKHF_UP) {
+			system->m_curKeyStatus[keyb.vkCode] = false;
+		} else {
+			system->m_curKeyStatus[keyb.vkCode] = true;
+		}
+		if((keyb.flags & LLKHF_INJECTED)== LLKHF_INJECTED) {
+		}
+	}
+	else {
+		system->m_curKeyStatus[keyb.vkCode] = true;
+	}
+	
+	return CallNextHookEx(system->m_llKeyboardHook, nCode, wParam, lParam);
+}
 
 LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemWin32.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemWin32.h	2010-10-22 22:31:40 UTC (rev 32659)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemWin32.h	2010-10-22 22:58:12 UTC (rev 32660)
@@ -320,6 +320,11 @@
 	 * Windows call back routine for our window class.
 	 */
 	static LRESULT WINAPI s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
+	
+	/**
+	 * Low-level inspection of keyboard events
+	 */
+	static LRESULT CALLBACK s_llKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
 
 	/** The current state of the modifier keys. */
 	GHOST_ModifierKeys m_modifierKeys;
@@ -331,6 +336,10 @@
 	__int64 m_start;
 	/** AltGr on current keyboard layout. */
 	bool m_hasAltGr;
+	/** holding hook handle for low-level keyboard handling */
+	HHOOK m_llKeyboardHook;
+	bool m_prevKeyStatus[255]; /* VK_* codes 0x01-0xFF, with 0xFF reserved */
+	bool m_curKeyStatus[255]; /* VK_* codes 0x01-0xFF, with 0xFF reserved */
 };
 
 inline void GHOST_SystemWin32::retrieveModifierKeys(GHOST_ModifierKeys& keys) const





More information about the Bf-blender-cvs mailing list