简体   繁体   中英

SendKeys.send is sending more than one character

sorry for my bad english.

I am writing a keyboard application for the touchscreen. but,

for example, when I press the A key, sometimes it's writes 5 times A key . I am using basically button click event.

private void button42_Click(object sender, EventArgs e)
    {
        SendKeys.Send("A");
        Thread.Sleep(100);
    }

there is no problem with the mouse_click event. just touch

how can i do it?

1.Try handling it in a mouse_up or touch_up event instead of using a delay here. Actual implementation and events will depend on you framework.

mouse_up /touch_up will make sure that you even only fires when touch is released.

To add repetition on touch and hold, you may have to add additional logic however.

  1. Try declaring a field to toggle the value of event fired.

     private bool handling=false; private void button42_Click(object sender, EventArgs e) { if(!handling) { handling=true; SendKeys.Send("A"); Task.Delay(100).Wait(); handling=false; } }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM