Hello, i have scanner 2d honeywell xenon 1900, it work like hid-keyboard.
in my program i use hooker for keyboard, which intercept press keys on keybord
and when i press on keyboard in english layout - hooker understand virtual_code and scan_code of keys
but when qr code consist english character, hooker ignored their because functions
ToAsciiEx or ToUnicodeEx can't translate virtual-code to character
for all english chracter my hooker show:
virtual code - 164
scan code - 56
in 'atol driver for scanners' in test read it show so
in qr code "abc абв" programm show "097098099 #32 абв"
but when cursor in notepad all characters correct
i use standart function:
[StructLayout(LayoutKind.Sequential)]
private class KeyboardHookStruct
{
public uint vkCode;
public uint scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}
... ... ... ...
private const int WH_KEYBOARD_LL = 13;
... ... ... ...
private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
{
bool handled = false;
if ((nCode >= 0) && (KeyDown != null || KeyUp != null || KeyPress != null))
{
KeyboardHookStruct MyKeyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
if (KeyDown != null && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))
{
Keys keyData = (Keys)MyKeyboardHookStruct.vkCode;
KeyEventArgs e = new KeyEventArgs(keyData);
KeyDown(this, e);
handled = handled || e.Handled;
}
if (KeyPress != null && wParam == WM_KEYUP)
{
bool isDownShift = ((GetKeyState(VK_SHIFT) & 0x80) == 0x80 ? true : false);
bool isDownCapslock = (GetKeyState(VK_CAPITAL) != 0 ? true : false);
byte[] keyState = new byte[256];
GetKeyboardState(keyState);
byte[] inBuffer = new byte[2];
int localeId = GetKeyboardLayoutId();
if (ToUnicodeEx(MyKeyboardHookStruct.vkCode,
MyKeyboardHookStruct.scanCode,
keyState,
inBuffer,
2,
0
, localeId
) >= 1)
{
UnicodeEncoding uEn = new UnicodeEncoding();
string outKey = uEn.GetString(inBuffer);
foreach (char key in outKey)
{
KeyPressEventArgs e = new KeyPressEventArgs(key);
KeyPress(this, e);
handled = handled || e.Handled;
}
}
}
if (KeyUp != null && (wParam == WM_KEYUP || wParam == WM_SYSKEYUP))
{
Keys keyData = (Keys)MyKeyboardHookStruct.vkCode;
KeyEventArgs e = new KeyEventArgs(keyData);
KeyUp(this, e);
handled = handled || e.Handled;
}
}
if (handled)
return 1;
else
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}
may be somebody write for scanners, what's mistake?
sorry for my english...