简体   繁体   中英

Sendkeys.send Ignoring messagebox

Anytime a message box or a custom box is suppose to be displayed in the program is bypassed when the sendkeys command is sent. For example:

SendKeys.Send("{F7}");
if (e.KeyCode == Keys.F7)
{
    DialogResult dialogResult = 
        MessageBox.Show("Are you sure you want to cancel the transacation", 
        "Cancel Trans", MessageBoxButtons.YesNo);

    if (dialogResult == DialogResult.Yes)
    {
        //clear the trans
        textBox1.Text = "";
        textBox1.Focus();
    }
    else
    {
        //close con goes back 
    }
}

If i hit f7 on my keyboard I actually see this and can choose

If I use the sendkeys command it doesn't display this and automatically hits yes has anyone ran into this i have tried the sendkeys.sendwait command but it does the same thing just takes longer.

OK i Apologize i am sending the key command as such

SendKeys.Send(""+command+"");

the command contains {f7} which is pulled from a database

I Figured out the issue although i had a message box showing the right command there was some other information hidden in there i guess

command=command.trim();
SendKeys.Send(""+command+"");

Trimming the command first fixed whatever issue there was with it sorry to be a burden on everyone

I figured out what needed to be done i needed to trim my command before it was sent there apparently was some hidden characters

command=command.trim();
SendKeys.Send(""+command+"");

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