eig
eig

Reputation: 231

How to hook keystroke to change from "C" to "Ctrl+C" in .NET?

In specific time period, when user presses "C" I want it to happen as user presses "Ctrl+C". Actually, whatever key user presses the program should adds Ctrl with it.

DO you know how to do that .NET ?

I've look around for changing KeyEventArgs.KeyData but it cannot be set.

Upvotes: 8

Views: 492

Answers (2)

Icono123
Icono123

Reputation: 3950

Uses this if you want to send keys:

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);
    }
}

Upvotes: 0

Oded
Oded

Reputation: 498904

KeyEventArgs.KeyData represents what they user actually pressed.

You can create a new KeyEventArgs with the KeyData you want and pass that around.

Upvotes: 4

Related Questions