[英]How to detect a Windows 8 Slate
I'm looking for a method to programatically detect Windows 8 Slate devices using C/C++. 我正在寻找一种使用C / C ++以编程方式检测Windows 8 Slate设备的方法。 My definition of "Slate" is "a portable computing device equipped with a touchscreen but without a dedicated physical keyboard" (so including devices that come with a keyboard dock, but excluding laptops and tradition tablets where the physical keyboard is attached).
我对“ Slate”的定义是“一种配备有触摸屏但没有专用物理键盘的便携式计算设备”(因此包括带有键盘底座的设备,但不包括连接了物理键盘的笔记本电脑和传统平板电脑)。
I tried using WMI Win32_SystemEnclosure and checking the ChassisTypes, but one Slate reported the ChassisTypes as being "Hand Held" and another reported "Main System Chassis", so this doesn't seem to be reliable. 我尝试使用WMI Win32_SystemEnclosure并检查ChassisType,但是一个Slate报告该ChassisType为“手持”,另一个报告“ Main System Chassis”,因此这似乎不可靠。
I'm not able to provide any code, since I don't have a "slate" device to test it on, but I can offer you some suggestions. 我无法提供任何代码,因为我没有“平板”设备可以对其进行测试,但是我可以为您提供一些建议。
You'll probably want to use a heuristic sort of approach, using several API calls to determine the presence or status of various bits of hardware, then determine if the system matches what you're looking for. 您可能需要使用一种启发式的方法,即使用多个API调用来确定硬件各种位的存在或状态,然后确定系统是否与您要查找的内容匹配。 The GetSystemMetrics API is likely to be the most useful to you;
GetSystemMetrics API可能对您最有用; after looking through some documentation, here are the calls that are likely to help you.
在阅读了一些文档之后,以下电话可能会为您提供帮助。
GetSystemMetrics
with SM_CONVERTIBLESLATEMODE
: returns 0 if the system is in Slate Mode and non-zero otherwise. 带有
SM_CONVERTIBLESLATEMODE
GetSystemMetrics
:如果系统处于Slate模式,则返回0, SM_CONVERTIBLESLATEMODE
返回非零。 There's no guarantee this will mean the system is an actual slate device, but it can at least tell you if the device has a slate mode and is using it. 无法保证这将意味着系统是实际的平板设备,但它至少可以告诉您该设备是否具有平板模式并正在使用它。
GetSystemMetrics
with SM_DIGITIZER
: returns a bitfield value that tells you whether the system supports touch or a pen. 带有
SM_DIGITIZER
GetSystemMetrics
:返回一个位域值,该值告诉您系统支持触摸还是笔。 If GetSystemMetrics(SM_DIGITIZER) & TABLET_CONFIG_NONE
evaluates to true, your device probably isn't a slate. 如果
GetSystemMetrics(SM_DIGITIZER) & TABLET_CONFIG_NONE
评估为true,则您的设备可能不是平板。 You can also make good use of the other bitflags this call gives you access to. 您还可以充分利用此调用允许您访问的其他位标志。
GetSystemMetrics
with SM_MOUSEPRESENT
: tells you whether a mouse is present. 带有
SM_MOUSEPRESENT
GetSystemMetrics
:告诉您是否存在鼠标。 This is a very weak test since the docs say virtual mice or sometimes just a mouse port will be enough to set this flag, but it's still worth testing. 这是一个非常弱的测试,因为文档说虚拟鼠标或有时只是一个鼠标端口就足以设置此标志,但是仍然值得测试。 If a mouse isn't present, your device has a higher chance of being a slate.
如果没有鼠标,则您的设备更有可能成为平板电脑。
GetSystemMetrics
with SM_TABLETPC
: similar to the SM_DIGITIZER
test, this tells you if the Tablet PC Input service is started or not. 带有
SM_TABLETPC
GetSystemMetrics
:类似于SM_DIGITIZER
测试,它告诉您Tablet PC Input服务是否已启动。 If the service isn't started, your device probably isn't a tablet. 如果服务未启动,则您的设备可能不是平板电脑。
GetSystemPowerStatus
could provide a few useful heuristics as well. GetSystemPowerStatus
也可以提供一些有用的试探法。 This API returns a SYSTEM_POWER_STATUS
structure which you can test in the following ways: 该API返回
SYSTEM_POWER_STATUS
结构,您可以通过以下方式进行测试:
ACLineStatus
is 0, your device isn't connected to AC power, so it's more likely to be a slate. ACLineStatus
为0,则表明您的设备未连接交流电源,因此很有可能是平板电脑。 BatteryFlag
is 128, there is no system battery, so your device probably isn't a slate. BatteryFlag
为128,则没有系统电池,因此您的设备可能不是平板。 If it's any other value (except 255, which is unknown status) there is a battery, which means your device is more likely to be a slate. You can also look into WMI's Win32_Keyboard , in particular its Availability
, ConfigManagerErrorCode
, and Status
properties. 您还可以查看WMI的Win32_Keyboard ,特别是其
Availability
, ConfigManagerErrorCode
和Status
属性。 At the end of the day there is no way to determine whether keyboard input is from a physical or virtual keyboard , but you can at least attempt to test for a physical keyboard. 最终, 无法确定键盘输入是来自物理键盘还是虚拟键盘 ,但是您至少可以尝试测试物理键盘。
Your WMI Win32_SystemEnclosure test would become another heuristic in the list. 您的WMI Win32_SystemEnclosure测试将成为列表中的另一种启发式方法。 See what
ChassisTypes
returns: Desktop
, Low Profile Desktop
, Mini Tower
, Tower
, and Laptop
probably mean the device isn't a slate. 查看
ChassisTypes
返回的内容: Desktop
, Low Profile Desktop
, Mini Tower
, Tower
和Laptop
可能意味着该设备不是平板电脑。 Pizza Box
, Portable
, Notebook
(although generally notebook == laptop in common verbiage, so this will require testing), Hand Held
, Space Saving
, and Lunch Box
are probably more likely to be slates. Pizza Box
, Portable
, Notebook
(尽管通常笔记本电脑==普通笔记本电脑,所以需要测试), Hand Held
, Space Saving
和Lunch Box
可能更容易选择。 You can also try to run calculations on the Depth
, Height
, Width
and Weight
properties, since anything over a certain size and weight probably won't be a portable device and therefore won't be a slate. 您还可以尝试在
Depth
, Height
, Width
和Weight
属性上运行计算,因为任何超过一定大小和重量的东西都可能不是便携式设备,因此也不是平板。
Sample touch detection code from MSDN : 来自MSDN的示例触摸检测代码:
// test for touch
int value = GetSystemMetrics(SM_DIGITIZER);
if (value & NID_READY){ /* stack ready */}
if (value & NID_MULTI_INPUT){
/* digitizer is multitouch */
MessageBoxW(hWnd, L"Multitouch found", L"IsMulti!", MB_OK);
}
if (value & NID_INTEGRATED_TOUCH){ /* Integrated touch */}
I'm not a specialist when it comes to WinAPI, but since noone else answered, maybe it will be of some help to you. 在WinAPI方面,我不是专家,但是由于没有其他人回答,因此也许会对您有所帮助。 On MSDN, there's a list of functions awailable for Windows store apps, which also specifies whether functions can be used on handheld devices.
在MSDN上,有Windows商店应用程序可使用的功能列表,该列表还指定是否可以在手持设备上使用这些功能。 Seems like the
Windows.Devices.Enumeration
contains exactly what you need - the DeviceInformation
class . 好像
Windows.Devices.Enumeration
包含的正是您所需要的DeviceInformation
类 。
All you have to do is list all the devices (there's code one the page which says how to do that), and search the list for a keyboard. 您所要做的就是列出所有设备(页面上有一个代码,其中列出了操作方法),然后在列表中搜索键盘。
Please note: I don't own any Windows 8 device, so I can't really test if this is helpful or not. 请注意:我没有任何Windows 8设备,因此我无法真正测试这是否有帮助。 Give it a try, and I'll delete my comment if it won't help you out.
请尝试一下,如果对您没有帮助,我会删除我的评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.