GetRawInputData USB Keyboard with Power keys

M

Milan

I am trying to access USB keyboard with Power keys (Power, Sleep and
WakeUp). I have tried to register HID Raw data using the following
code:

UINT nDevices;
PRAWINPUTDEVICELIST pRawInputDeviceList;
if (GetRawInputDeviceList(NULL, &nDevices,
sizeof(RAWINPUTDEVICELIST)) != 0) {
return 0;
}
pRawInputDeviceList = (RAWINPUTDEVICELIST
*)malloc(sizeof(RAWINPUTDEVICELIST) * nDevices);
GetRawInputDeviceList(pRawInputDeviceList, &nDevices,
sizeof(RAWINPUTDEVICELIST));
wsprintf(rawinputdevices,"Number of raw input devices: %i\n\n",
nDevices);
MessageBox(NULL, rawinputdevices, "", MB_OK);
// after the job, free the RAWINPUTDEVICELIST
free(pRawInputDeviceList);

RAWINPUTDEVICE Rid[50];
Rid[0].usUsagePage = 0x01;
Rid[0].usUsage = 0x06;
Rid[0].dwFlags =0;// RIDEV_NOLEGACY;
Rid[0].hwndTarget = NULL;

Rid[1].usUsagePage = 0x01;
Rid[1].usUsage = 0x80;
Rid[1].dwFlags =0;// RIDEV_NOLEGACY;
Rid[1].hwndTarget = NULL;
if (RegisterRawInputDevices(Rid, 2, sizeof (Rid [0])) == FALSE) {
wsprintf(mousemessage,"RawInput init failed:\n");
MessageBox(NULL, mousemessage, "", MB_OK);
//registration failed.
}


After successful registration, I am watching for the WM_INPUT messages
in the WndProc:

case WM_INPUT:
{
UINT dwSize;

GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize,
sizeof(RAWINPUTHEADER));
LPBYTE lpb = new BYTE[dwSize];
if (lpb == NULL)
{
return 0;
}

if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize,
sizeof(RAWINPUTHEADER)) != dwSize )
MessageBox(NULL, TEXT("GetRawInputData doesn't return correct size
!\n"), "", MB_OK);

RAWINPUT* raw = (RAWINPUT*)lpb;

TCHAR szTempOutput[3000];
TCHAR szOutput[30000];

HRESULT hResult;

if (raw->header.dwType == RIM_TYPEKEYBOARD)
{

hResult = StringCchPrintf(szTempOutput, 3000, TEXT(" Kbd:
make=%04x Flags:%04x Reserved:%04x ExtraInformation:%08x, msg=%04x
VK=%04x \n"),
raw->data.keyboard.MakeCode,
raw->data.keyboard.Flags,
raw->data.keyboard.Reserved,
raw->data.keyboard.ExtraInformation,
raw->data.keyboard.Message,
raw->data.keyboard.VKey);
if (FAILED(hResult))
{
// TODO: write error handler
} MessageBox(NULL, szTempOutput, "", MB_OK);
}
else if (raw->header.dwType == RIM_TYPEMOUSE)
{
hResult = StringCchPrintf(szTempOutput, STRSAFE_MAX_CCH,
TEXT("Mouse: usFlags=%04x ulButtons=%04x usButtonFlags=%04x
usButtonData=%04x ulRawButtons=%04x lLastX=%04x lLastY=%04x
ulExtraInformation=%04x\r\n"),
raw->data.mouse.usFlags,
raw->data.mouse.ulButtons,
raw->data.mouse.usButtonFlags,
raw->data.mouse.usButtonData,
raw->data.mouse.ulRawButtons,
raw->data.mouse.lLastX,
raw->data.mouse.lLastY,
raw->data.mouse.ulExtraInformation);

if (FAILED(hResult))
{
// TODO: write error handler
} MessageBox(NULL, szTempOutput, "", MB_OK);
}
else if (raw->header.dwType == RIM_TYPEHID)
{
hResult = StringCchPrintf(szTempOutput, STRSAFE_MAX_CCH,
TEXT("Hid: bRawData=%04x dwCount=%04x dwSizeHid=%04x \r\n"),
raw->data.hid.bRawData,
raw->data.hid.dwCount,
raw->data.hid.dwSizeHid);

if (FAILED(hResult))
{
// TODO: write error handler
}
// print first byte
MessageBox(NULL, szTempOutput, "", MB_OK);
// whole message
char bRawData[3000];
strncpy(bRawData, (char*)&raw->data.hid.bRawData[0],
(int)(raw->data.hid.dwSizeHid*raw->data.hid.dwCount));
// send raw bytes to the dump
application
sendText2(bRawData,
(int)(raw->data.hid.dwSizeHid*raw->data.hid.dwCount), 5001);
}


delete[] lpb;
break; // return 0;
}

The problem is that I can receive raw keyboard data for all keys
EXCEPT power keys. I don't know how to receive Power keys raw data. Do
I need to register for the proper Usage Page and Id? How to find out
which Usage Page to use?

I have found hclient.exe and here is the dump:

Device 124. UsagePage 01, Usage 02 // mouse, isn't it?
Device 136, UsagePage 01, Usage 080 // what is this?
Device 80, UsagePage 01, Usage 06 // keyboard?

USB Keyboard is Focus Electronic and is called FK7200 USB. It has
trackball with two mouse buttons on it.

Why this keyboard doesn't have UsagePage 07?
 
Top