I am calling this function from C#: GetKeyboardStatus()
Looking at the documentation it says that it returns a bit mask value. The goal of my code is to determine if the device has a physical keyboard with alphanumeric characters. I have successfully called this function and the return value is 15. However since I don't understand bit masks, I don't know how to compare it to the 0x0008 value, which according to the documentation "Indicates whether or not the keyboard hardware has alphanumeric keys.". I am not tagging this as a Windows Mobile or Compact Framework question because I think all you will need to understand to answer my question is bit masks and C# and I am hoping the answer will expand my understanding of how to work with a bit mask (not required though). Here is my code. I think the only part that is wrong is the return statement:
public static bool HasAlphaNumericKeys {
get {
const uint KBDI_KEYBOARD_ALPHA_NUM = 0x0008;
uint returnValue = GetKeyboardStatus();
return returnValue == KBDI_KEYBOARD_ALPHA_NUM;
}
}
[DllImport("coredll")]
private static extern uint GetKeyboardStatus();
Thanks for trying to help but I have discovered that this is not a reliable way to determine if there is a physical keyboard with alphanumeric keys. I tried 2 devices, one with a keyboard and one without and the GetKeyboardStatus function returned 15 for both of them, so I can't even test the explanation of bit masks in the answers.
Try
return (returnValue & KBDI_KEYBOARD_ALPHA_NUM) != 0;
This returns true if bit 3 of returnValue is set, regardless of the values of any of the other bits in returnValue.