MediatedCommunications / WindowsInput

Capture and Simulate Keyboard and Mouse Input
MIT License
111 stars 17 forks source link

When Capturing Global Keyboard Control+Shift+2 throws error #6

Closed Davidobot closed 1 year ago

Davidobot commented 4 years ago

Having keyboard = WindowsInput.Capture.Global.KeyboardAsync(); in the program is enough to replicate this. Pressing CTRL+SHIFT+2 throws the error below:

System.ArgumentOutOfRangeException
  HResult=0x80131502
  Message=Index and length must refer to a location within the string.
Parameter name: length
  Source=mscorlib
  StackTrace:
   at System.String.Substring(Int32 startIndex, Int32 length)
   at WindowsInput.Events.Sources.KeyboardEventSourceState.ToUnicodeEx(KeyboardLayout Layout, KeyboardState Keyboard, ToUnicodeExFlags Flags, KeyCode VKey, Int32 SKey, String& Value)
   at WindowsInput.Events.Sources.KeyboardEventSourceState.TryGetCharFromKeyboardState(KeyCode virtualKeyCode, Int32 scanCode, ToUnicodeExFlags fuState, KeyboardLayout Layout, String& chars)
   at WindowsInput.Events.Sources.GlobalKeyboardEventSource.GetTextClick(GlobalKeyboardMessage Message, KeyboardHookStruct keyboardHookStruct)
   at WindowsInput.Events.Sources.GlobalKeyboardEventSource.Callback(CallbackData data)
   at WindowsInput.Events.Sources.HookEventSource.HookProcedure(Int32 nCode, IntPtr wParam, IntPtr lParam)

  This exception was originally thrown at this call stack:
    string.Substring(int, int)
    WindowsInput.Events.Sources.KeyboardEventSourceState.ToUnicodeEx(WindowsInput.Native.KeyboardLayout, WindowsInput.Native.KeyboardState, WindowsInput.Events.Sources.ToUnicodeExFlags, WindowsInput.Events.KeyCode, int, out string)
    WindowsInput.Events.Sources.KeyboardEventSourceState.TryGetCharFromKeyboardState(WindowsInput.Events.KeyCode, int, WindowsInput.Events.Sources.ToUnicodeExFlags, WindowsInput.Native.KeyboardLayout, out string)
    WindowsInput.Events.Sources.GlobalKeyboardEventSource.GetTextClick(WindowsInput.Native.GlobalKeyboardMessage, WindowsInput.Native.KeyboardHookStruct)
    WindowsInput.Events.Sources.GlobalKeyboardEventSource.Callback(WindowsInput.Native.CallbackData)
    WindowsInput.Events.Sources.HookEventSource.HookProcedure(int, System.IntPtr, System.IntPtr)

EDIT: Bug present in 6.1.1 but not 6.1.0

TonyValenti commented 4 years ago

@Davidobot - I tested on the latest sources but couldn't recreate the issue. Can you give that a try and let me know? I might need to push a new nuget package.

If it does happen:

  1. What order do you press the keys in
  2. What "Version" of the keys do you press? ie: Left Control, Right Shift, Keypad 2.
TonyValenti commented 4 years ago

Also, what language is your keyboard in?

Davidobot commented 4 years ago
  1. What order do you press the keys in

In the order of control + shift + 2

  1. What "Version" of the keys do you press? ie: Left Control, Right Shift, Keypad 2.

Left control, left shift and top-row 2

The keyboard is set to US. This was actually reported as a bug by a user of my program, but I was able to replicate it.

TonyValenti commented 2 years ago

I am not abel to replicate this in the latest version. Is it still happening?