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 8208147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:14:33+00:00 2026-06-07T09:14:33+00:00

I have to use hotkeys which will be working from every window and pulpit.

  • 0

I have to use hotkeys which will be working from every window and pulpit. In winforms I used:

RegisterHotKey(this.Handle, 9000, 0x0002, (int)Keys.F10);

and

UnregisterHotKey(this.Handle, 9000);

and

protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);
    switch (m.Msg)
    {
        case 0x312:
        switch (m.WParam.ToInt32())
        {
            case 9000:
            //function to do
            break;
        }
        break;
    }
}

In my WPF aplication I tried do:

AddHandler(Keyboard.KeyDownEvent, (KeyEventHandler)HandleKeyDownEvent);

and

private void HandleKeyDownEvent(object sender, KeyEventArgs e)
{
    if (e.Key == Key.F11 && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
    {
        //function to do
    }
}    

But it works only when my application is active and on the top, but it doesn’t work when the application is minimized (for example). Is any method to do it?

  • 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-06-07T09:14:34+00:00Added an answer on June 7, 2026 at 9:14 am

    You can use the same approach as in WinForms with some adaptation:

    • use WindowInteropHelper to get HWND (instead of Handle property of a form)
    • use HwndSource to handle window messages (instead of overriding WndProc of a form)
    • don’t use Key enumeration from WPF – it’s values are not the ones you want

    Complete code:

    [DllImport("User32.dll")]
    private static extern bool RegisterHotKey(
        [In] IntPtr hWnd,
        [In] int id,
        [In] uint fsModifiers,
        [In] uint vk);
    
    [DllImport("User32.dll")]
    private static extern bool UnregisterHotKey(
        [In] IntPtr hWnd,
        [In] int id);
    
    private HwndSource _source;
    private const int HOTKEY_ID = 9000;
    
    protected override void OnSourceInitialized(EventArgs e)
    {
        base.OnSourceInitialized(e);
        var helper = new WindowInteropHelper(this);
        _source = HwndSource.FromHwnd(helper.Handle);
        _source.AddHook(HwndHook);
        RegisterHotKey();
    }
    
    protected override void OnClosed(EventArgs e)
    {
        _source.RemoveHook(HwndHook);
        _source = null;
        UnregisterHotKey();
        base.OnClosed(e);
    }
    
    private void RegisterHotKey()
    {
        var helper = new WindowInteropHelper(this);
        const uint VK_F10 = 0x79;
        const uint MOD_CTRL = 0x0002;
        if(!RegisterHotKey(helper.Handle, HOTKEY_ID, MOD_CTRL, VK_F10))
        {
            // handle error
        }
    }
    
    private void UnregisterHotKey()
    {
        var helper = new WindowInteropHelper(this);
        UnregisterHotKey(helper.Handle, HOTKEY_ID);
    }
    
    private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        const int WM_HOTKEY = 0x0312;
        switch(msg)
        {
            case WM_HOTKEY:
                switch(wParam.ToInt32())
                {
                    case HOTKEY_ID:
                        OnHotKeyPressed();
                        handled = true;
                        break;
                }
                break;
        }
        return IntPtr.Zero;
    }
    
    private void OnHotKeyPressed()
    {
        // do stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a website on which we have use parallax effect. In
Telephone Manager give me Null phone number while i have use this code -
i make one class file for jar. and this class have use wurfl. and
I have been trying to register 3 hotkeys. I followed this example (or this
I have an application which uses hotkeys which are to be defined by the
I have some commands that use Ctrl-Win- as hotkeys. However, MenuItem displays these as
I have a dialog box that allows users to set hotkeys for use in
I have use these code to upload two images in folder of the root
I have use semantic-analyze-proto-impl-toggle to switch between the function's proto and impl, but when
I have use include ('base.php') script in my other scripts ( more.php ). Now

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.