Monday, May 17, 2010

Enable/Disable System Inputs (Keyboard/Mouse)

If you want to enable/disable you system input including mouse/keyboard, you may use "BlockInput" from user32.dll

VB6
Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'call following where requierd
'this will block input for 5 seconds
DoEvents
BlockInput True
Sleep 5000
BlockInput False

C#
using System.Runtime.InteropServices;

[DllImport("user32.dll")]
static extern bool BlockInput(bool fBlockIt);


Console.WriteLine(BlockInput(True));
System.Threading.Thread.Sleep(5000);
Console.WriteLine(BlockInput(False));


No comments:

Post a Comment