Desktop.Robot icon indicating copy to clipboard operation
Desktop.Robot copied to clipboard

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

Open nagilum opened this issue 3 years ago • 4 comments

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..

nagilum avatar May 27 '21 08:05 nagilum

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!

lucassklp avatar Jun 13 '21 14:06 lucassklp

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,

EightNetNz avatar Jul 26 '21 01:07 EightNetNz

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.

olivercoad avatar Aug 12 '21 05:08 olivercoad

@EightNetNz This PR fixes that

lucassklp avatar Nov 07 '21 15:11 lucassklp