.NET sendkeys到计算器 [英] .NET sendkeys to calculator

查看:65
本文介绍了.NET sendkeys到计算器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的sendkeys代码在记事本上很好用,但在计算器上不起作用。问题是什么? (与我在这里发送的内容相比,这是另一个问题。 .NET程序中的发送密钥问题

The sendkeys code below works well for Notepad but it doesn't work for Calculator. What is the problem? (It's another problem compared to what I sent here Sendkeys problem from .NET program)

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("User32")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
private void button1_Click(object sender, EventArgs e)
{
    IntPtr calculatorHandle = FindWindow("SciCalc", "Calculator");
    //IntPtr calculatorHandle = FindWindow("Notepad", "Untitled - Notepad");
    if (calculatorHandle == IntPtr.Zero)
    {
        MessageBox.Show("Calculator is not running.");
        return;
    }
    SetForegroundWindow(calculatorHandle);
    System.Threading.Thread.Sleep(1000);
    SendKeys.SendWait("111*11=");
    //SendKeys.SendWait("{ENTER}");
    //cnt++;
    SendKeys.Flush();
}


推荐答案

我会告诉你如何您可以弄清楚如何将击键发送到calc.exe。

I'll tell you how you can figure out how to send keystorkes to calc.exe.

使用spy ++监视calc.exe窗口进程中的消息。为此,请进入spy ++,然后单击日志消息工具栏按钮。将光标拖到calc.exe窗口上。我给出的说明是针对VS2008的,对于其他VS版本中包含的Spy ++,它们可能略有不同。但是相同的功能始终可用。

Use spy++ to monitor the messages on the calc.exe window process as you're using it. To do this go into spy++ and click on the log messages toolbar button. Drag the cursor onto the calc.exe window. The instructions I gave are for VS2008, they may differ slightly for the Spy++ included in other VS versions. But the same functionality has always been available.

在输入文本时,您将确切地看到发送了什么消息。您需要执行相同的操作。

You will see exactly what messages are sent as you are entering text. You need to do the same.

使用Win32 API SendMessage ,LPARAM和WPARAM到找到的窗口句柄。

Use the Win32 API SendMessage, LPARAM and WPARAM to your found window handle.

这篇关于.NET sendkeys到计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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