C # SendKeys.Send

I run the problem using the C # SendKeys.Send method. I am trying to replace keyboard keys with other keys, for example, when I press "a" on the keyboard, I want this key to be "s", for example, when I do this in my code:

if ((Keys)keyCode== Keys.A)
{                    
    SendKeys.Send("s");                    

}

Right now I get only the “sa” character typed in my notebook, but instead of typing “sa”, I need to get only the “s” character in this case, because when I press “a” on my keyboard, there should be replaced by "s".

I tried to remove the last character by adding this line:

SendKeys.Send("{BS}");

But all I have is the symbol "s", and there was the symbol "a".

How can I prevent this?

+5
9

, . . , .

0

:

SendKeys.Send("{BS}");

SendKeys.Send("S");

EDIT ( ):

( ), , ( "a" ), , unicode , " ? , , , , ...

+2

, , , :

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == 'a')
    {
        e.Handled = true;
    }
}

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.A)
    {
        e.Handled = true;
        SendKeys.Send("s");
    }
}

:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == 'a')
    {
        e.Handled = true;
        SendKeys.Send("s");
    }
}

, , backspace s s?

if ((Keys)keyCode== Keys.A)
{                    
    SendKeys.Send("{BS}"); // remove A
    SendKeys.Send("s");    // add S
}
+2

, , - Low-Level , . P/Invoke, , .

+2

"a", backspace "s", "s". ?

.....

s?

if ((Keys)keyCode== Keys.A)
            {
                Sendkeys.Send("{BS}"); // Deletes the "A" (already sent)
                SendKeys.Send("s"); // Sends the "S"
            }
+1

SendKeys.SendWait

+1

, SendKeys.Send("{BS}"); ( ). , / SendKeys.Send. , - key-down/key-up , , (, ).

+1

Have you tried switching .Send({BS})to .Send("s")? Otherwise, can you clarify?

0
source

All Articles