.NET/ユーザーが無操作の状態を取得する・GetLastInputInfo
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* ユーザーがキーボードやマウスなど無操作の状態を取得する...
ユーザーがマウスやキーボードなどの操作をしていない状態の...
サンプルコードは C#, Visual Basic(VB)になります。
#htmlinsert(windev-top.html)
#contents
* 関連サイト [#be8faa15]
-[[Microsoft | Windowsデベロッパーセンター GetLastInputIn...
* 動作環境 [#n8992965]
- Windows 10 ver.1909
- Visual Studio 2019
- .NET Framework 4.7.2
- コンソールアプリケーション
* サンプルコード [#rcf6224a]
ユーザーがコンピュータを操作していない状態を取得したい場...
本サンプルコードは、無操作状態の監視のみになるので、実際...
** 動作 [#v6aa9a48]
以下のサンプルコードを実行すると、以下のような動作になり...
キーボードやマウスを触る(操作する)と終了するだけです。
#ref(A01.gif)
** C# サンプルコード [#y9999300]
using System;
internal struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
class Program
{
[System.Runtime.InteropServices.DllImport("User32.dl...
private static extern bool
GetLastInputInfo(ref LASTINPUTINFO plii);
static void Main(string[] args)
{
Console.WriteLine("Start : GetLastInputInfo API ...
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)System.Runtime.InteropS...
uint operation_time = 0;
bool operation = false;
while (!operation)
{
try
{
if (!GetLastInputInfo(ref lastInPut))
{
throw new System.ComponentModel.Win3...
}
if (operation_time == 0) { operation_tim...
if (operation_time != lastInPut.dwTime) ...
}
catch (Exception ex)
{
Console.WriteLine("Exception:{0}", ex.Me...
}
System.Threading.Thread.Sleep(100);
}
Console.WriteLine("Stop: ** You touched the comp...
}
}
** Visual Basic(VB) サンプルコード [#m4470fd6]
Module Module1
Friend Structure LASTINPUTINFO
Public cbSize As UInteger
Public dwTime As UInteger
End Structure
<Runtime.InteropServices.DllImport("User32.dll")>
Private Function GetLastInputInfo(ByRef plii As LAST...
End Function
Sub Main()
Console.WriteLine("Start : GetLastInputInfo API ...
Dim lastInPut As LASTINPUTINFO = New LASTINPUTIN...
lastInPut.cbSize = CUInt(System.Runtime.InteropS...
Dim operation_time As UInteger = 0
Dim operation As Boolean = False
While Not operation
Try
If Not GetLastInputInfo(lastInPut) Then
Throw New System.ComponentModel.Win3...
End If
If operation_time = 0 Then
operation_time = lastInPut.dwTime
End If
If operation_time <> lastInPut.dwTime Then
operation = True
End If
Catch ex As Exception
Console.WriteLine("Exception:{0}", ex.Me...
End Try
Threading.Thread.Sleep(100)
End While
Console.WriteLine("Stop: ** You touched the comp...
End Sub
End Module
以上、ユーザーがコンピュータを操作していない状態を取得す...
#htmlinsert(windev-btm.html)
終了行:
#navi(../)
* ユーザーがキーボードやマウスなど無操作の状態を取得する...
ユーザーがマウスやキーボードなどの操作をしていない状態の...
サンプルコードは C#, Visual Basic(VB)になります。
#htmlinsert(windev-top.html)
#contents
* 関連サイト [#be8faa15]
-[[Microsoft | Windowsデベロッパーセンター GetLastInputIn...
* 動作環境 [#n8992965]
- Windows 10 ver.1909
- Visual Studio 2019
- .NET Framework 4.7.2
- コンソールアプリケーション
* サンプルコード [#rcf6224a]
ユーザーがコンピュータを操作していない状態を取得したい場...
本サンプルコードは、無操作状態の監視のみになるので、実際...
** 動作 [#v6aa9a48]
以下のサンプルコードを実行すると、以下のような動作になり...
キーボードやマウスを触る(操作する)と終了するだけです。
#ref(A01.gif)
** C# サンプルコード [#y9999300]
using System;
internal struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
class Program
{
[System.Runtime.InteropServices.DllImport("User32.dl...
private static extern bool
GetLastInputInfo(ref LASTINPUTINFO plii);
static void Main(string[] args)
{
Console.WriteLine("Start : GetLastInputInfo API ...
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)System.Runtime.InteropS...
uint operation_time = 0;
bool operation = false;
while (!operation)
{
try
{
if (!GetLastInputInfo(ref lastInPut))
{
throw new System.ComponentModel.Win3...
}
if (operation_time == 0) { operation_tim...
if (operation_time != lastInPut.dwTime) ...
}
catch (Exception ex)
{
Console.WriteLine("Exception:{0}", ex.Me...
}
System.Threading.Thread.Sleep(100);
}
Console.WriteLine("Stop: ** You touched the comp...
}
}
** Visual Basic(VB) サンプルコード [#m4470fd6]
Module Module1
Friend Structure LASTINPUTINFO
Public cbSize As UInteger
Public dwTime As UInteger
End Structure
<Runtime.InteropServices.DllImport("User32.dll")>
Private Function GetLastInputInfo(ByRef plii As LAST...
End Function
Sub Main()
Console.WriteLine("Start : GetLastInputInfo API ...
Dim lastInPut As LASTINPUTINFO = New LASTINPUTIN...
lastInPut.cbSize = CUInt(System.Runtime.InteropS...
Dim operation_time As UInteger = 0
Dim operation As Boolean = False
While Not operation
Try
If Not GetLastInputInfo(lastInPut) Then
Throw New System.ComponentModel.Win3...
End If
If operation_time = 0 Then
operation_time = lastInPut.dwTime
End If
If operation_time <> lastInPut.dwTime Then
operation = True
End If
Catch ex As Exception
Console.WriteLine("Exception:{0}", ex.Me...
End Try
Threading.Thread.Sleep(100)
End While
Console.WriteLine("Stop: ** You touched the comp...
End Sub
End Module
以上、ユーザーがコンピュータを操作していない状態を取得す...
#htmlinsert(windev-btm.html)
ページ名: