Global Hotkey does not work in Fullscreen game
Asked Answered
S

2

6

I am creating a program for taking screenshots of a game, out of the game. When I press the hotkey it works, but with the open game in fullscreen it does not detect the key.

My code:

protected override void WndProc(ref Message m)
{
    const int WM_HOTKEY = 0x0312;

    switch (m.Msg)
    {
        case WM_HOTKEY:
        {
            if ((short)m.WParam == 1)
            {
                start = DateTime.Now;
                progressBar1.Maximum = 1;
                progressBar1.Step = 1;
                progressBar1.Value = 0;

                DoRequest();
            }
            break;
        }

        default:
        {
            base.WndProc(ref m);
            break;
        }
    }
}

I register the global key using:

RegisterHotKey(this.Handle, 1, (int)KeyModifier.None, Keys.F11);

Help-me :/

SOLVED! Resolved, I managed to fix through this project: http://www.codeproject.com/Articles/19004/A-Simple-C-Global-Low-Level-Keyboard-Hook

Thank you all!

Semolina answered 20/1, 2014 at 0:50 Comment(0)
R
3

The problem with most games (not all of them) is that they use DirectInput (DirectX) and not windows message pump to read keystrokes. I have also written an application using voice recognition that sends keys to games and experienced the same issue which I solved by looking at DirectX keycodes. ref: DirectInput

Rhododendron answered 20/1, 2014 at 5:58 Comment(3)
How can I implement this in my code? I do not get it right, i tried to put the F11 key of DirectX and did not work.Semolina
Please see if the following link msdn.microsoft.com/en-us/library/windows/desktop/… can assist you.Rhododendron
Thanks, I managed through this project: codeproject.com/Articles/19004/…Semolina
F
3

I had a similar problem but I solved it by running my program with Admin privileges.

Favien answered 17/6, 2017 at 10:48 Comment(2)
Awesome, but still actual :) ThanksIasis
This actually fixed the problem for me!! Thanks... I made a global hook keys app but didnt work while my game is running until I saw your answer and realized that my game is running as admin while the app is not. Thanks such a life saverSuppletory

© 2022 - 2024 — McMap. All rights reserved.