Foam/home Every ? ? Washington Tool NT bean knowledge Win32 programming note Private terminology Joke Variety Game miscellaneous notes Favorites Bulletin board Mail
Windows XP So using Raw Input API which joins, it tries enumerating the input device which is connected to the system. In case of the keyboard, it outputs also type and sub type. Temporarily it tries putting out summary to debugging output. Using AutoArray which the apprentice was lifted easily, it increases, but to use in the production, being to be weak, whether the one which you do not use that way is better. It is redundancy, but.
It is necessary to define WINVER=0x500 or _WIN32_WINNT=0x0501 with compiling option and the like.
1: | template <class T> |
2: | class AutoArray { |
3: | public: |
4: | AutoArray(size_t n) |
5: | { |
6: | #ifdef _DEBUG |
7: | // For checking the buffer overrun, excessively one alocate |
8: | m_ptr = new T[n + 1]; |
9: | #else |
10: | m_ptr = new T[n]; |
11: | #endif |
12: | if (m_ptr) { |
13: | m_size = n; |
14: | #ifdef _DEBUG |
15: | // The sentry is put in place |
16: | FillMemory(&m_ptr[n], sizeof m_ptr[n], SENTINEL); |
17: | #endif |
18: | } |
19: | else { |
20: | m_size = 0; |
21: | } |
22: | |
23: | } |
24: | ~AutoArray() |
25: | { |
26: | #ifdef _DEBUG |
27: | if (m_ptr) { |
28: | PBYTE pb = reinterpret_cast<PBYTE>(&m_ptr[m_size]); |
29: | ASSERT(pb); |
30: | // Check of buffer overrun |
31: | for (int i = 0; i < sizeof m_ptr[m_size]; ++i) { |
32: | ASSERT(pb[i] == SENTINEL); |
33: | } |
34: | } |
35: | #endif |
36: | delete[] m_ptr; |
37: | } |
38: | |
39: | bool OK() |
40: | { |
41: | return m_ptr != NULL; |
42: | } |
43: | |
44: | operator T*() |
45: | { |
46: | return m_ptr; |
47: | } |
48: | |
49: | T& operator[](size_t n) |
50: | { |
51: | ASSERT(n < m_size); |
52: | return m_ptr[n]; |
53: | } |
54: | |
55: | protected: |
56: | // to prohibit copy operations |
57: | AutoArray(const AutoArray<T>&); |
58: | AutoArray<T> operator=(const AutoArray<T>&); |
59: | |
60: | enum { SENTINEL = 0xcc }; |
61: | |
62: | protected: |
63: | T* m_ptr; |
64: | size_t m_size; |
65: | }; |
66: | |
67: | bool KeyboardList() |
68: | { |
69: | // Acquiring the number of input devices which presently are connected |
70: | UINT nInputDevices; |
71: | if (GetRawInputDeviceList(NULL, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { |
72: | return false; |
73: | } |
74: | |
75: | // Acquiring the fundamental information of the input device |
76: | AutoArray<RAWINPUTDEVICELIST> rawinputDeviceList(nInputDevices); |
77: | if (!rawinputDeviceList.OK()) { |
78: | return false; |
79: | } |
80: | UINT ntmp = nInputDevices; |
81: | if (GetRawInputDeviceList(rawinputDeviceList, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) != ntmp) { |
82: | return false; |
83: | } |
84: | |
85: | int nKbd = 0; // The number of keyboards which are connected |
86: | |
87: | for (UINT i = 0; i < nInputDevices; ++i) { |
88: | // Acquiring the length of device name |
89: | UINT size; |
90: | if (GetRawInputDeviceInfo(rawinputDeviceList[i].hDevice, RIDI_DEVICENAME, NULL, &size) != 0) { |
91: | return false; |
92: | } |
93: | // Acquiring device name |
94: | AutoArray<TCHAR> name(size); |
95: | if (!name.OK()) { |
96: | return false; |
97: | } |
98: | if ((int)GetRawInputDeviceInfo(rawinputDeviceList[i].hDevice, RIDI_DEVICENAME, name, &size) < 0) { |
99: | return false; |
100: | } |
101: | // Information of device |
102: | static const TCHAR* deviceTypeNames[] = { |
103: | _T("Mouse"), |
104: | _T("Keybd"), |
105: | _T("HID "), |
106: | }; |
107: | TRACE3("[%02d] %s hDevice=%p", i, deviceTypeNames[rawinputDeviceList[i]. dwType], rawinputDeviceList[i].hDevice); |
108: | TRACE1(" %s\n", name); |
109: | |
110: | if (rawinputDeviceList[i].dwType == RIM_TYPEKEYBOARD) { |
111: | // When it is the keyboard, type sub type the |
112: | ++nKbd; |
113: | |
114: | RID_DEVICE_INFO devinfo = { sizeof devinfo, }; |
115: | UINT sz = sizeof devinfo; |
116: | if ((int)GetRawInputDeviceInfo(rawinputDeviceList[i]. hDevice, RIDI_DEVICEINFO, &devinfo, &sz) < 0) { |
117: | return false; |
118: | } |
119: | ASSERT(devinfo.dwType == RIM_TYPEKEYBOARD); |
120: | TRACE2(" ==> [0x%02x, 0x%02x]\n", devinfo.keyboard.dwType, devinfo.keyboard.dwSubType); |
121: | } |
122: | } |
123: | |
124: | TRACE1("Number of keyboards: %d\n", nKbd); |
125: | |
126: | return true; |
127: | } |
As for example of output such feeling:
[00] Keybd hDevice=00010063 \??\Root#RDP_KBD#0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd} ==> [0x51,0x00] [01] Keybd hDevice=00010061 \??\Root#*PNP030b#1_0_22_0_32_0#{884b96c3-56ef-11d1-bc8c-00a0c91405dd} ==> [0x04,0x00] [02] Mouse hDevice=0001004B \??\Root#RDP_MOU#0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd} [03] Mouse hDevice=00010049 \??\HID#Vid_045e&Pid_0040#6&31accd24&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd} Number of keyboards: 2
Type=4, Subtype=0 In other words, they are the generally known 101 keyboards. Type=0x51 undefined type, with in the sense that you say. But originally you do not have to be,, when INF is not just set with the USB keyboard, because type becomes unclear, undefined type is allotted helplessly. It is digression, but and it seems that is the case which uses the same product ID with 106 with 101 depending upon the manufacturer. Because the device is identified bender by ID product ID, it means not to be able allot separate type to 101 and 106. Don't you think? with the worst case, even with INF the way there is no this. It seems the unexpectedly many way but... Microsoft as beginning 。
Windows XP As for the empty, it can connect the plural keyboards the machine ??, dynamic layout switching it joined. with USB and the like, but furthermore this time recognizing the type sub type of 101/106, etc. the machine ? ? that it does., changes keyboard layout dynamically, the special machine ? ? for Japan and Korea it does, but the machine ? ? have entered. those where it is supported with in-box 101/106/are three types of NEC even in English edition. The dynamic layout switching securely the machine ? ? ?, being to be convenient, it does, but in order to decide keyboard layout with type sub type, in case of unclear type = 0x51 it does not operate well. Because it cannot distinguish the type of keyboard, it seems that is adjusted to the setting of the PS/2 keyboard helplessly. As for only this on OS side the way because it is not, only it has preparing correct INF at vendor each company of the USB keyboard. You intend probably to write the utility which sets the unreasonable doing type among those, but there is no circumstance plug time.... In order to make the dynamic layout switching effective, Japanese keyboard layout (xxxx0411 the thing) it is necessary to make active. Being machine ?? to be imbedded to Japanese keyboard layout, for example it does. because the machine ? ? which is not it does to the keyboard layout of US, when the dynamic layout switching is not effective, first active ????????? and that keyboard layout the main point ?? coming and others. Furthermore the RDP device, those where it becomes type = 0x51 with output example of the ? are the hypothetical device for ??????. Because it has not been related with the hardware of specification, it is thought as the thing which becomes the type of obscurity.
ホーム ざれごと ワシントン州 ツール NT豆知識 Win32プログラミングノート 私的用語 ジョーク いろいろ ゲーム雑記 Favorites 掲示板 Mail