如何自动决定是否在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键盘(!!),所以这样的功能永远不会告诉你没有键盘。 - Giel 9小时前