如何挂钩击键在.NET中从“C”更改为“Ctrl + C”?

时间:2010-03-16 12:00:59

标签: c# .net keyboard

在特定时间段内,当用户按下“C”时,我希望在用户按下“Ctrl + C”时发生。实际上,无论关键用户按下该程序,都应该添加Ctrl。

你知道如何做.NET吗?

我一直在寻找更改KeyEventArgs.KeyData,但无法设置。

2 个答案:

答案 0 :(得分:4)

KeyEventArgs.KeyData表示用户实际按下的内容。

您可以使用所需的KeyData创建新的KeyEventArgs并传递它。

答案 1 :(得分:0)

如果要发送密钥,请使用此选项:

using System;

namespace System.Windows.Forms
{
    // Summary:
    //     Provides methods for sending keystrokes to an application.
    public class SendKeys
    {
        // Summary:
        //     Processes all the Windows messages currently in the message queue.
        public static void Flush();
        //
        // Summary:
        //     Sends keystrokes to the active application.
        //
        // Parameters:
        //   keys:
        //     The string of keystrokes to send.
        //
        // Exceptions:
        //   System.InvalidOperationException:
        //     There is not an active application to send keystrokes to.
        //
        //   System.ArgumentException:
        //     keys does not represent valid keystrokes
        public static void Send(string keys);
        //
        // Summary:
        //     Sends the given keys to the active application, and then waits for the messages
        //     to be processed.
        //
        // Parameters:
        //   keys:
        //     The string of keystrokes to send.
        public static void SendWait(string keys);
    }
}