如何自动决定是否在 Windows 中显示虚拟键盘?
我们正在我们的应用程序中添加对手势和虚拟键盘的支持,但是当我连接了真实键盘时不想看到虚拟键盘......
谢谢!
更新:RRUZ(他没有 win8 平板电脑)有一个有用的建议,但没有奏效,因为 win8 平板电脑的行为不符合预期。
To get the number of keyboards present in the system you can use the Win32_Keyboard WMI class.
Try this sample
{$APPTYPE CONSOLE}
uses
SysUtils,
ActiveX,
ComObj,
Variants;
function GetKeyboardCount : integer;
var
FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
begin;
Result:=0;
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '');
FWbemObjectSet:= FWMIService.ExecQuery('SELECT DeviceID FROM Win32_Keyboard','WQL', $00000020);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
Inc(Result);
FWbemObject:=Unassigned;
end;
end;
begin
try
CoInitialize(nil);
try
Writeln(Format('Keyboards %d', [GetKeyboardCount]));
finally
CoUninitialize;
end;
except
on E:EOleException do
Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
on E:Exception do
Writeln(E.Classname, ':', E.Message);
end;
Writeln('Press Enter to exit');
Readln;
end.
以我的经验,这在现实世界中无济于事:在我的 Win8 平板电脑上,设备管理器报告了一个 PS/2 键盘(!!),所以像这样的函数永远不会告诉你没有键盘。– 吉尔 9 小时前