Click here to Skip to main content
15,905,004 members
Home / Discussions / Hardware & Devices
   

Hardware & Devices

 
GeneralRe: DSL question Pin
code-frog10-Apr-08 15:45
professionalcode-frog10-Apr-08 15:45 
GeneralRe: DSL question Pin
#realJSOP11-Apr-08 3:06
professional#realJSOP11-Apr-08 3:06 
GeneralRe: DSL question Pin
code-frog15-Apr-08 3:30
professionalcode-frog15-Apr-08 3:30 
GeneralRe: DSL question Pin
Dan Neely15-Apr-08 4:33
Dan Neely15-Apr-08 4:33 
GeneralSuspect problem from power supply Pin
Mekong River3-Apr-08 0:14
Mekong River3-Apr-08 0:14 
GeneralRe: Suspect problem from power supply Pin
Matthew Butler3-Apr-08 3:09
Matthew Butler3-Apr-08 3:09 
GeneralRe: Suspect problem from power supply Pin
Luc Pattyn3-Apr-08 4:43
sitebuilderLuc Pattyn3-Apr-08 4:43 
GeneralHooking Raw Input - Detect HID mice Pin
maszup2-Apr-08 0:01
maszup2-Apr-08 0:01 
Hello

I need to write an application to recognize which USB HID Mouse is using at the moment. At least two mice are connected to the PC at one time. It should work in background and show in the background window or write to file movement positions of currently moving mouse in the system.

My way of thinking is to:
1) create main application (exe or DLL) with window which will:
- detects all Raw Input HID mouses but not regist them yet
- recieve messages from its window and from hooking DLL
- detects in seperate thread which window is currently on top (Foreground)
- if new window is on top call first RegisterRawInputDevices with Handle to new window then call "CreateHook" from DLL to reset Hooks to new thread

Below the code for the thread detecting top most window:
	<br />
	while (Running) {<br />
		Sleep(1000);	<br />
                hWnd_curr = GetForegroundWindow();<br />
		if(hWnd_curr != hWnd_old) {<br />
			hWnd_old = hWnd_curr;<br />
			GetWindowText(hWnd_curr,window_name,sizeof(window_name));<br />
<br />
			Rid[0].hwndTarget = hWnd_curr;  //define to which window register raw input<br />
                        //here I get error: unused = CXX0030: Error: expression cannot be evaluated<br />
<br />
			if(!RegisterRawInputDevices(Rid, 1, sizeof (Rid[0]))) {<br />
				_snprintf(logevent,sizeof(logevent),"Register Raw Input Devices FAILED");<br />
				Write2File(logevent);<br />
				continue;<br />
			}<br />
	<br />
			if(pCreateHook != NULL && (dwThreadId = GetWindowThreadProcessId(hWnd_curr,&dwProcessId))!=0) <br />
						msgHook = pCreateHook(WH_CALLWNDPROC,hwndMain,dwThreadId);<br />
<br />
		}<br />
            }


Unfortunately I cannot register raw input devices to the other window than the one I created in main program.


2) create a DLL that that be using Global Hooks for all messages from the window that is on top. DLL will contains one external function:
- CreateHook - clears old hook if not NULL and sets new hook for given threadID
in the DLL there is a callback function for collecting hooked messages which are directly sent to main application

static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam) {<br />
	<br />
	if(nCode < 0) {<br />
		CallNextHookEx(hook, nCode, wParam, lParam);<br />
		return 0;<br />
	}<br />
<br />
	INFO f; <br />
	f.code=nCode; <br />
	f.hhook=hook; <br />
	f.lParam=lParam;<br />
<br />
	cwpMessageParams = (PMSG)lParam;<br />
<br />
	if(cwpMessageParams->message == WM_INPUT) <br />
		SendMessage(mForm, messageCode, (WPARAM)(cwpMessageParams->message), (LPARAM)&f);<br />
<br />
	return CallNextHookEx(hook, nCode, wParam, lParam);<br />
}


The second problem with is that this callback never gets WM_INPUT even if raw inputs are register to the window created in main application.

Any suggestions? Or maybe my way of thinking is wrong??
How is it possible to get at least the name of currently working mouse??

Thanks for any help
Maciek
GeneralRe: Hooking Raw Input - Detect HID mice Pin
Dave Kreskowiak2-Apr-08 3:45
mveDave Kreskowiak2-Apr-08 3:45 
GeneralRe: Hooking Raw Input - Detect HID mice Pin
maszup2-Apr-08 5:05
maszup2-Apr-08 5:05 
GeneralRe: Hooking Raw Input - Detect HID mice Pin
Randor 2-Apr-08 5:10
professional Randor 2-Apr-08 5:10 
GeneralRe: Hooking Raw Input - Detect HID mice Pin
maszup2-Apr-08 5:33
maszup2-Apr-08 5:33 
GeneralRe: Hooking Raw Input - Detect HID mice Pin
Randor 2-Apr-08 6:31
professional Randor 2-Apr-08 6:31 
AnswerRe: Hooking Raw Input - Detect HID mice Pin
maszup2-Apr-08 9:27
maszup2-Apr-08 9:27 
GeneralRe: Hooking Raw Input - Detect HID mice Pin
maszup7-Apr-08 21:56
maszup7-Apr-08 21:56 
GeneralRe: Hooking Raw Input - Detect HID mice Pin
Randor 12-Apr-08 20:30
professional Randor 12-Apr-08 20:30 
GeneralRe: Hooking Raw Input - Detect HID mice Pin
Dave Kreskowiak2-Apr-08 6:48
mveDave Kreskowiak2-Apr-08 6:48 
QuestionBuilding c# pc remote control? Pin
Goalie3531-Mar-08 17:22
Goalie3531-Mar-08 17:22 
AnswerRe: Building c# pc remote control? Pin
Matthew Butler2-Apr-08 14:56
Matthew Butler2-Apr-08 14:56 
GeneralRe: Building c# pc remote control? Pin
Goalie352-Apr-08 19:11
Goalie352-Apr-08 19:11 
GeneralRe: Building c# pc remote control? Pin
Matthew Butler3-Apr-08 2:57
Matthew Butler3-Apr-08 2:57 
GeneralMonitor blur Pin
Mekong River31-Mar-08 17:19
Mekong River31-Mar-08 17:19 
GeneralRe: Monitor blur Pin
Sebastian Schneider2-Apr-08 5:00
Sebastian Schneider2-Apr-08 5:00 
GeneralRe: Monitor blur Pin
Mekong River3-Apr-08 0:11
Mekong River3-Apr-08 0:11 
GeneralRe: Monitor blur Pin
Dave Kreskowiak3-Apr-08 3:47
mveDave Kreskowiak3-Apr-08 3:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.