13

キーボードとマウスの入力を防ぐコード (できれば C#) を探しています。

4

3 に答える 3

23

ジョシュの(正しい)答えを拡張します。そのメソッドの PInvoke シグネチャを次に示します。

public partial class NativeMethods {

    /// Return Type: BOOL->int
    ///fBlockIt: BOOL->int
    [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint="BlockInput")]
    [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern  bool BlockInput([System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] bool fBlockIt) ;

}

public static void BlockInput(TimeSpan span) {
  try { 
    NativeMethods.BlockInput(true);
    Thread.Sleep(span);
  } finally {
    NativeMethods.BlockInput(false);
  }
}

編集

一定間隔でブロックする方法を示すコードを追加しました

于 2009-02-25T15:55:13.900 に答える
7

BlockInput Win32 関数を調べる

楽しいテストのようですね :)

于 2009-02-25T15:49:16.317 に答える