1

I have this piece of code

private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        if(e.KeyCode== Keys.Z)
        {
            BarTimer.Value = 0;
            timer1.Start();
            timer1.Interval = 500;
            BarTimer.Minimum = 0;
            BarTimer.Maximum = 80;
        }
    }

And it works just fine, but I want to be able to press it when in a fullscreen application, so I can see the progress bar on my second monitor. Is there a property or something i can change to make it work like that?

dvs
  • 97
  • 1
  • 8

2 Answers2

1

If it's a single key you can use RegisterHotKey. There is sample code in this answer: how to use RegisterHotKey and the one linked in it. The Microsoft C++ documentation is here.

If you want to intercept all keyboard input you would need a keyhook. I suggest you google WH_KEYBOARD_LL and SetWindowsHookEx. But I don't think you can do this in c#; I've only ever seen key hooks written in C/C++. They will also cause some firewalls to take an interest - intercepting all keyboard input can be considered potentially hostile.

Community
  • 1
  • 1
Stuart Whitehouse
  • 1,421
  • 18
  • 30
1

Hi I know of a nice tutorial I found On code project. It worked for me when i needed something like this.

http://www.codeproject.com/Articles/19004/A-Simple-C-Global-Low-Level-Keyboard-Hook

Regards,

Cohenry
  • 21
  • 5