Categories
NETCF Windows Mobile

KeyboardPresent always returns false

This bug affects both managed and native developers working with the Windows Mobile 5.0 SDK.


Native


Due to an error in snapi.h the location of the registry key used to indicate if a hardware keyboard is present is incorrect:-


////////////////////////////////////////////////////////////////////////////////
// KeyboardPresent
// Gets a value indicating whether a keyboard is attached and enabled.
#define SN_KEYBOARDPRESENT_ROOT HKEY_LOCAL_MACHINE
#define SN_KEYBOARDPRESENT_PATH TEXT(“SoftwareMicrosoftShell”)
#define SN_KEYBOARDPRESENT_VALUE TEXT(“HasKeyboard”)


The root key for this value should instead be HKEY_CURRENT_USER. Once you use this location you can correctly determine if there is a hardware keyboard (this is the same location as used on WM2003 Second Edition devices such as the HTC Blue Angel).


Managed


The SystemState class also uses the incorrect location to read this value so the property will always return false. The workaround here is to access the registry directly using either the Microsoft.Win32.RegistryKey in .NETCF v2.0 e.g.


RegistryKey keyboardKey = Registry.CurrentUser.OpenSubKey(“SoftwareMicrosoftShell”);

int dwHasKeyboard = keyboardKey.GetValue(“HasKeyboard”, 0);

keyboardKey.Close();

bool hasKeyboard = (dwHasKeyboard != 0);

By Peter Foot

Microsoft Windows Development MVP