EasyAsABC123 / Keyboard

Background/Foreground Keyboard and Mouse input handler
102 stars 43 forks source link

Shift key handling #5

Open matosimi opened 7 years ago

matosimi commented 7 years ago

Hi, I like this project however I bumped into fact that it does not handle shift key properly... I am using it to send password characters (which obviously can contain capital letters and special characters that you type with shift key)... so this solution works well if you like to type "hello world3" however it does not work when you would like to type "Hello WoRLD#"... because capital letters will be replaced by normal ones...for the reason that this capitalization is somehow omitted in the code, yet it is quite prepared to support it... so here is my solution:

replace GetVirtualKeyCode method in Messaging.cs with following one:

public static uint GetVirtualKeyCode(char c, bool getShiftState = false)
{
 var helper = new Helper { Value = VkKeyScan(c) };
 byte virtualKeyCode = helper.Low;
 byte shiftState = helper.High;
 if (getShiftState)
  return shiftState;
 else return virtualKeyCode;
}

then replace Key(char c) constructor in Key.cs:

public Key(char c)
{
 _buttonCounter = 0; 
 Vk = (Messaging.VKeys)Messaging.GetVirtualKeyCode(c);
 ShiftKey = Messaging.VKeys.NULL;
 ShiftType = (Messaging.ShiftType)Messaging.GetVirtualKeyCode(c, true); 
}

...and suddenly Keyboard supports capital letters :)...and it can be tested with KeybordDemo right away.

EasyAsABC123 commented 7 years ago

Put in a PR and I'll accept it