Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to detect a keybd_event without focus
    text
    copied!<p>I'm working on a program, who need to detect when the user press the keyboard or use his mouse, even if the program is minimized or not focused. I think I have to use the windows API, keybd_event (user32), but I don't know how to use the "listener" of this event. I have something like that:</p> <pre><code> [DllImport("user32.dll")] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,UIntPtr dwExtraInfo); void PressKey(byte keyCode) { //My code here } </code></pre> <p>I did some research, but it's the first time I have to use DllImport, so I don't know how to continue ... Thanks (Ps:Sorry about my bad English, this is not my native language :) )</p> <p>(PPs: I've read all of your answers, but it takes a while to read every link, so I'll work on it tonight, but I think I will find the answer. Anyway, thanks for the links everybody ;) )</p> <p>Edit: So I just finished my code and it's work :) It looks something like:</p> <pre><code> [DllImport("user32.dll")] public static extern Boolean GetLastInputInfo(ref tagLASTINPUTINFO plii); public struct tagLASTINPUTINFO { public uint cbSize; public Int32 dwTime; } private void timerTemps_Inactif_Tick(object sender, EventArgs e) { tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; if (IdleTime &gt; 10000) { //My code here } } } </code></pre> <p>Thanks for the help guys ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload