Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6177857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:21:01+00:00 2026-05-24T00:21:01+00:00

I need to detect when a user presses Ctrl + V (regardless of window

  • 0

I need to detect when a user presses Ctrl+V(regardless of window focus – my app will likely be minimised) but I must not stop the actual paste operation.

I have tried a few things: (I am successfully binding to keystrokes with RegisterHotKey)

I have:

protected override void WndProc(ref Message m)
{
  if (m.Msg == 0x312)
    hotKey();
  base.WndProc(ref m);
}

and I’ve tried the following:

void hotKey()
{
  SendKeys.SendWait("^v"); //just puts 'v' instead of clipboard contents
}

and

void hotKey()
{
  SendKeys.SendWait(ClipBoard.GetText());
  /* This works, but since Ctrl is still down, it triggers
   * all the shortcut keys for the app, e.g. if the keyboard
   * contains 's' then instead of putting 's' in the app, it
   * calls Ctrl+S which makes the app think the user wants
   * to save.
   */
}

Currently the only working solution I have is to bind to something different, e.g. Ctrl+B and then call SendKeys.SendWait("^v"); however this isn’t ideal.

An ideal solution would be if my window didn’t intercept the keystroke in the first place, just reacted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:21:02+00:00Added an answer on May 24, 2026 at 12:21 am

    You can do this by leveraging hooks using SetWindowsHookEx().

    HHOOK WINAPI SetWindowsHookEx(
      __in  int idHook,
      __in  HOOKPROC lpfn,
      __in  HINSTANCE hMod,
      __in  DWORD dwThreadId
    );
    

    Basically, you can set up a low-level keyboard hook:

    _hookHandle = SetWindowsHookEx(
        WH_KEYBOARD_LL,
        KbHookProc,                   // Your keyboard handler
        (IntPtr)0,
        0);                           // Set up system-wide hook.
    

    to capture system-wide keyboard events. But it also allows you to make those keyboard events pass through to other apps. For your particular case, you can define KbHookProc as:

    private static int KbHookProc(int nCode, IntPtr wParam, IntPtr lParam)
    {
        if (nCode >= 0) // This means we can intercept the event.
        {
            var hookStruct = (KbLLHookStruct)Marshal.PtrToStructure(
                    lParam,
                    typeof(KbLLHookStruct));
    
            // Quick check if Ctrl key is down. 
            // See GetKeyState() doco for more info about the flags.
            bool ctrlDown = 
                    GetKeyState(VK_LCONTROL) != 0 ||
                    GetKeyState(VK_RCONTROL) != 0;
    
            if (ctrlDown && hookStruct.vkCode == 0x56) // Ctrl+V
            {
                // Replace this with your custom action.
                Clipboard.SetText("Hi");
            }
        }
    
        // Pass to other keyboard handlers. Makes the Ctrl+V pass through.
        return CallNextHookEx(_hookHandle, nCode, wParam, lParam);
    } 
    

    I coded a quick and dirty WinForms app to illustrate this. For the full code listing, see http://pastebin.com/uCSvqwb4.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to detect if the user is using an iPhone 4, but I
I am developing an Android app and I am need to detect user context
I need to detect the user finger-press, there's already the tap event, but tap
I need to initialize a variable when the user presses Ctrl - Alt -
For a navigation app, i need to detect when the user deviated from a
If user repeatedly presses back button, I need a way to detect when they
I need to be able to detect whether the current language my user is
I need to detect Image format to save a image like image1.jpg, image2.gif, but
I have a Win32 form with a TEdit control. When the user presses CTRL-t
I need to detect whether the user has pressed the dot key in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.