lucassklp / Desktop.Robot

A library used to control your mouse and keyboard programmatically in .NET Core
MIT License
139 stars 23 forks source link

Add support for different case of text and modifiers when using the Type function #11

Open nagilum opened 3 years ago

nagilum commented 3 years ago

I want to send the keypresses for the string "This is a test!" but it turns into "this is a test1". I'm assuming the letters are reduced to their respective key and the modifiers aren't kept. So "T" becomes "t" and "!" becomes "1" because the "!" characters is a modifier of the "1" button on my keyboard. (Norwegian)

I tried to use robot.CombineKeys(Key.Shift, Key.T); to get the upper case T, which worked, but it would be nice if the Type() function handled that for me.

The exclamation point didn't work with robot.CombineKeys(Key.Shift, Key.One); tho. For some reason it printed "Z" to me..

lucassklp commented 3 years ago

Sorry for delaying on reply. What SO are you using?

By the way, I think you're using the wrong function. CombineKeys may works, but this method is not supposed to do what you want. Try using this overload of Type funcion:

robot.Type(Key.Shift, Key.T); https://github.com/lucassklp/Desktop.Robot/blob/main/Desktop.Robot/Extensions/TypingExtension.cs#L30

Regarding the problem related to Shift + 1, I'll check it out!

EightNetNz commented 2 years ago

In Keys.cs windows Keycode for numbers Zero to Nine are all 0x5A same as 'Z', should be 0x30 - 0x39.

    ...

    [Keycode(Platform = "OSX", Keycode = 0x06)]
    [Keycode(Platform = "Windows", Keycode = **0x5A**)]
    [Keycode(Platform = "Linux", Keycode = 0x007a)]
    Z,

    //Numbers
    [Keycode(Platform = "OSX", Keycode = 0x30)]
    [Keycode(Platform = "Windows", Keycode = **0x5A**)]
    [Keycode(Platform = "Linux", Keycode = 0x0030)]
    Zero,
olivercoad commented 2 years ago

Try using this overload of Type funcion: robot.Type(Key.Shift, Key.T);

I don't think that would work, it'll just press shift and then t without holding shift. CombineKeys is the correct method to use for that.

lucassklp commented 2 years ago

@EightNetNz This PR fixes that