通过wmi可以获取当前连接的键盘的名称等信息,但将键盘拔下后,获取的信息依然不变。
是不是应通过其他方法获取该动作?
谢谢!
是不是应通过其他方法获取该动作?
谢谢!
解决方案 »
- 谁能给我一个 初学者适合学的hook api完整程序呢?
- 有点难:如何根据rc文件中的对话框模板,解析出对话框图片,又没有现成的代码?
- 关于图象匹配,
- ●请问如何发送一段文字(或者Ctrl+A,TAB等)到屏幕的鼠标指针所在位置???如果当前屏幕在网页上呢???或者当前位置是DOS窗口???
- 如何将文件中某行设为当前屏?
- VC超简单
- 想做一个通讯录 该怎样下手
- VC简单问题来者有分!
- 想学习VC++的图像处理,但不知道从何处着手?
- 安装了VC++60,找不到MSDN,无法安装帮助文件
- 关于socket的几个问题(发送完消息是否需要关闭等)
- [界面版公告]针对已解决问题不揭帖的处理-本贴谢绝UP之类的回复
你确认这样可以监测到键盘拔出吗?能否讲详细一点,或者有没有demo程序参考一下呢?
void CWndMessDlg::OnDeviceChange(WPARAM wParam,LPARAM lParam)
{
UINT Event = (UINT) wParam;
PDEV_BROADCAST_HDR pHDR = (PDEV_BROADCAST_HDR) lParam;
CString strMes ;
switch(Event) {
case DBT_CONFIGCHANGECANCELED:
strMes = "A request to change the current configuration (dock or undock) has been canceled. ";
break;
case DBT_CONFIGCHANGED:
strMes = "The current configuration has changed, due to a dock or undock.";
break;
case DBT_DEVICEARRIVAL:
strMes = "A device has been inserted and is now available. " ;
strMes += "\n";
switch(pHDR->dbch_devicetype) {
case DBT_DEVTYP_OEM :
strMes += "OEM- or IHV-defined device type. ";
break;
case DBT_DEVTYP_VOLUME:
strMes += " Logical volume. ";
break;
case DBT_DEVTYP_PORT:
strMes += " Port device (serial or parallel). ";
break;
default:
break;
}
break;
case DBT_DEVICEQUERYREMOVE :
strMes = "Permission is requested to remove a device. Any application can deny this request and cancel the removal. ";
break;
case DBT_DEVICEQUERYREMOVEFAILED:
strMes = "A request to remove a device has been canceled. ";
break;
case DBT_DEVICEREMOVECOMPLETE:
strMes = "A device has been removed. ";
break;
case DBT_DEVICEREMOVEPENDING:
strMes = "A device is about to be removed. Cannot be denied. ";
break;
case DBT_DEVICETYPESPECIFIC:
strMes = "A device-specific event has occurred. ";
break;
case DBT_QUERYCHANGECONFIG:
strMes = "Permission is requested to change the current configuration (dock or undock). ";
break;
case DBT_USERDEFINED:
strMes ="The meaning of this message is user-defined. ";
break;
default:
break;
}
AfxMessageBox(strMes);}
还有一个 afx_msg void OnDevModeChange(WPARAM wParam,LPARAM lParam);
ON_MESSAGE(WM_DEVMODECHANGE,OnDevModeChange)
void CWndMessDlg::OnDevModeChange(WPARAM wParam,LPARAM lParam)
{
CString str = (LPTSTR )lParam;
AfxMessageBox(str);
}
它的lParam的解释如下:
lParam
Pointer to a structure identifying the device removed. The structure consists of an event-independent header, followed by event-dependent members that describe the device. To use this structure, treat the structure as a DEV_BROADCAST_HDR structure, then check its dbch_devicetype member to determine the device type.重要的是最后一句,也就是DEV_BROADCAST_HDR的第二个参数dbch_devicetype,你再去看下这个里面,应该可以得到启示了
这个参数的值可以为DBT_DEVTYP_PORT这个结构体,再跟下去看下,第四个参数(设备名称)
dbcp_name
Pointer to a null-terminated string specifying the friendly name of the port or the device connected to the port. Friendly names are intended to help the user quickly and accurately identify the device—for example, "COM1" and "Standard 28800 bps Modem" are considered friendly names.我也不太确定,如果我们的键盘是接在PS/2接口上,应该这里填上这个就可以了
应该就可以搜索到键盘了呵呵,我也只是看了MSDN做下猜测,不对之处,见谅