//register first raw input devices.
RAWINPUTDEVICE raw;
Raw. HwndTarget=AfxGetMainWnd () - & gt; M_hWnd;
Raw. UsUsagePage=0 x01;
Raw. UsUsage=0 x02;//mouse raw. UsUsage=0 x06;//keyboard
Raw. DwFlags=RIDEV_INPUTSINK;
if(! RegisterRawInputDevices (& amp; Raw, 1, sizeof (RAWINPUTDEVICE)))
MessageBox (L "registered the keyboard equipment failure," L "registered raw input device");
//class wizard add message response function in the program
Void CmagickeyDlg: : OnRawInput (UINT nInputcode, HRAWINPUT HRAWINPUT)
{
If (RIM_INPUT==nInputcode)//what is the meaning of this sentence
{
Return CDialogEx: : OnRawInput (nInputcode hRawInput);
}
//the following obtain input data
LPBYTE LPB=nullptr;
UINT uint_size;
GetRawInputData (hRawInput, RID_INPUT nullptr, & amp; Uint_size, sizeof (the RAWINPUTHEADER));
LPB=new BYTE [uint_size];
If (nullptr==LPB)
{
MessageBox (L "not allocate memory," L "Raw Input Test");
The delete [] LPB;
Return CDialogEx: : OnRawInput (nInputcode hRawInput);
}
If (GetRawInputData (hRawInput, RID_INPUT LPB, & amp; Uint_size, sizeof (the RAWINPUTHEADER))!=uint_size)
{
MessageBox (L "GetRawInputDate dosen" t return correct size!" , L "Raw Input Test");
The delete [] LPB;
Return CDialogEx: : OnRawInput (nInputcode hRawInput);
}
The RAWINPUT raw=* (LPB) (the RAWINPUT *); The delete [] LPB;//delete first, afraid of forget
//here is to capture the data operation
}
Now this can only capture the keyboard or mouse, cannot capture the keyboard and mouse at the same time,
How to set up to capture at the same time the keyboard and mouse?
CodePudding user response:
VS the IDE in don't understand the symbol on the right mouse button, choose to define,CodePudding user response:
RAWINPUTDEVICE raw [2].
Raw [0]. HwndTarget=AfxGetMainWnd () - & gt; M_hWnd;
Raw [0]. UsUsagePage=0 x01;
Raw [0]. UsUsage=0 x02;//mouse
Raw [0]. DwFlags=RIDEV_INPUTSINK;
Raw [1]. HwndTarget=AfxGetMainWnd () - & gt; M_hWnd;
Raw [1]. UsUsagePage=0 x01;
Raw [1]. UsUsage=0 x06;//keyboard
Raw [1]. DwFlags=RIDEV_INPUTSINK;
if(! RegisterRawInputDevices (& amp; Raw [0], 2, 2 * sizeof (RAWINPUTDEVICE)))
MessageBox (L "registered the keyboard equipment failure," L "registered raw input device");
Give it a try, not to,
CodePudding user response:
Ok, thank you zhao4zhong1,CodePudding user response:
RAWINPUTDEVICE raw [2].
Raw [0]. HwndTarget=AfxGetMainWnd () - & gt; M_hWnd;
Raw [0]. UsUsagePage=0 x01;
Raw [0]. UsUsage=0 x02;//mouse
Raw [0]. DwFlags=RIDEV_INPUTSINK;
Raw [1]. HwndTarget=AfxGetMainWnd () - & gt; M_hWnd;
Raw [1]. UsUsagePage=0 x01;
Raw [1]. UsUsage=0 x06;//keyboard
Raw [1]. DwFlags=RIDEV_INPUTSINK;
if(! RegisterRawInputDevices (& amp; Raw [0], 2, 2 * sizeof (RAWINPUTDEVICE)))//cannot register, the array can only register
MessageBox (L "registered the keyboard equipment failure," L "registered raw input device");
CodePudding user response: