watin 中的关键笔画 [英] Key strokes in watin

查看:32
本文介绍了watin 中的关键笔画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的 watin 应用按下 down 键,但我不知道该怎么做.我在之前的一篇文章中看到过,你应该使用:

I am trying to get my watin app to push the down key but i cant see how to do it. I have seen it in a previous post you should use :

System.Windows.Forms.SendKeys.SendWait("{DOWN}"); 

但这对我不起作用,因为我使用的是网络浏览器,有什么建议吗?

but this wont work for me as im using a web browser, any suggestions?

推荐答案

您需要告诉 Windows 将其焦点设置在浏览器窗口上,然后发送正确的键盘命令.

You need to tell Windows to set it's focus on the Browser Window, and then send the correct key command.

例如,此代码段将焦点设置到浏览器并将向下"键发送到浏览器窗口.

For instance, this code snippet will set focus to the browser and send the "DOWN" key to the browser window.

[DllImport("user32.dll")]
private static extern IntPtr SetFocus(IntPtr hWnd);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);

private void SendDownKey(Browser browser)
{
    SetForegroundWindow(browser.document.DomContainer.hWnd);
    SetFocus(browser.document.DomContainer.hWnd);      

    SendKeys.SendWait("{DOWN}");
}

这篇关于watin 中的关键笔画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆