-1

I'm having a challenge with scancodes, and how to convert these to virtual key codes & ASCII.

I'm using the Interception/Oblita library to retrieve all scancodes coming from a barcode scanner. Regular strokes keystrokes like "A" "!" and not an issue forwarding via the InputSimulator library (Link: https://www.nuget.org/packages/InputSimulator/)

The problems appear when trying to forward special characters like ¨ or ` using a Danish keyboard layout.

I receive these scancodes when inputting ¨ (Keydown)

56 82 79 77 72

Which should correspond to L-Alt + 0168 But when converting to Virtual keys, i get this result: L-ALT + INSERT + END + RIGHT + UP

I map the keys using MapVirtualKey from user32 dll, with the scancode and maptype = 1 (MAPVK_VSC_TO_VK)

How can I map them correctly so I get the Alt key combination? is it because I need to map using another p-invoke method?

behzad
  • 801
  • 3
  • 15
  • 33
MMM
  • 311
  • 5
  • 14
  • 30
  • Could you please explain the generic flow ? Barcode readers are reading barcodes, and converting them to the characters and sending read characters to the OS like those characters were typed on the keyboard. You can configure the reader to send Enter key after this also. Why do you need the `oblitum/Interception` library (that remaps one key code to another) and the `inputsimulator` (that can send virtual key codes to the OS) ? Can you use bracode reader output "as is" ? – oleksa Jan 02 '20 at 10:40
  • @oleksa i cannot use it as is, unfortuantley. i need the oblitum framework to intercept all keys coming in, for me to measure on the input, so if a special barcode comes in, i might need to redirect it through a com-port. – MMM Jan 02 '20 at 10:49
  • 1
    well, the [MapVirtualKey documentation](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mapvirtualkeya) says that you need to use the `MapVirtualKeyEx` to put keyboard layout into account. Is it possible that you need to use the `MapVirtualKeyEx` with Danish keyboard characters ? – oleksa Jan 02 '20 at 10:56
  • 1
    please check if [this answers](https://stackoverflow.com/questions/318777/c-sharp-how-to-translate-virtual-keycode-to-char) your question. Please write the simple reproduce case that uses the MapVirtualKey mapping, like [I've just created](https://gist.github.com/oleksabor/e7f92e30f347da9616fda175c4fd33a9) and show it with certain explanation – oleksa Jan 02 '20 at 11:02

1 Answers1

1

After long periods with trials and errors, i seem to solve the problem. In the interception library there is a "Send" method, for forwarding the captured keystrokes - i don't know why i haven't used this method before, because it solves the conversion problem.

MMM
  • 311
  • 5
  • 14
  • 30