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

Cannot type uppercase symbols

Open LeeeJoe opened this issue 3 years ago • 0 comments

Hi. Cannot type uppercase symbols:

using Desktop.Robot;
using Desktop.Robot.Extensions;

using System.Text.RegularExpressions;

DoTask();

void DoTask()
{
    const string s1 = "~!@#$%^&*()_+{}|:\"<>?";
    const string s2 = "VaLeri+buHattI+2022  ~~ !! @@ ## $$ %% ^^ && ** (( )) __ ++ {{ }} || :: \"\" << >> ??";

    var robot = new Robot();
    robot.AutoDelay = 10;

    string s;
    Console.WriteLine("Hello world!\n");
    Console.WriteLine($"String to type 1:\n{s1}\n");
    Console.WriteLine($"String to type 2:\n{s2}\n");

    Task.Run(async () => 
    {
        await Task.Delay(1000);

        s = s1;
        robot.Type(s);
        robot.Type("  ");

        // Insert from clipboard
        robot.KeyDown(Key.Shift);
        robot.KeyPress(Key.Insert);
        robot.KeyPress(Key.Insert);
        robot.KeyPress(Key.Insert);
        robot.KeyUp(Key.Shift);

        robot.Type("  ");
        s = s2;

        for (int i = 0; i < s.Length; i++)
        {
            if (IsUpperSymbol(s[i]) || Regex.IsMatch(s[i].ToString(), "[A-Z]"))
            {
                robot.KeyDown(Key.Shift);
                robot.KeyPress(s[i]);
                robot.KeyUp(Key.Shift);
            }
            else
            {
                robot.KeyPress(s[i]);
            }
        }

        robot.KeyPress(Key.Enter);
    });

    s = Console.ReadLine();

    Console.WriteLine($"\nEntered string is:\n{s}");
}

bool IsUpperSymbol(char ch)
{
    bool res = false;
    char[] chars = { '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?' };

    foreach (var c in chars)
    {
        if (c == ch)
        {
            res = true;
            break;
        }
    }

    return res;
}

Windows output (clipboard = #):

Hello world!

String to type 1: ~!@#$%^&*()_+{}|:"<>?

String to type 2: VaLeri+buHattI+2022 ~~ !! @@ ## $$ %% ^^ && ** (( )) __ ++ {{ }} || :: "" << >> ??

`1234567890-=[];',./ ### VaLeri+buHattI+2022 ~~ !! @@ ## $$ %% ^^ && ** (( )) __ ++ {{ }} || :: "" << >> ??

Entered string is: `1234567890-=[];',./ ### VaLeri+buHattI+2022 ~~ !! @@ ## $$ %% ^^ && ** (( )) __ ++ {{ }} || :: "" << >> ??

Linux, Centos 8 output (clipboard = $):

Hello world!

String to type 1: ~!@#$%^&*()_+{}|:"<>?

String to type 2: VaLeri+buHattI+2022 ~~ !! @@ ## $$ %% ^^ && ** (( )) __ ++ {{ }} || :: "" << >> ??

No protocol specified `12345678()-=[];<./ VaLeri=buHattI=2022 `` 11 22 33 44 55 66 77 88 (( )) -- == [[ ]] \ ;; << .. //

Entered string is: `12345678()-=[];<./ VaLeri=buHattI=2022 `` 11 22 33 44 55 66 77 88 (( )) -- == [[ ]] \ ;; << .. //

LeeeJoe avatar Jun 17 '22 12:06 LeeeJoe