Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

Commit 395b66d

Browse files
authored
Merge pull request #542 from NotCoffee418/GetLastInputInfo
Add User32.GetLastInputInfo
2 parents f9ae958 + ac44163 commit 395b66d

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

src/User32/PublicAPI.Unshipped.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ static extern PInvoke.User32.EnumDisplaySettings(char* lpszDeviceName, uint iMod
4444
static extern PInvoke.User32.EnumDisplaySettingsEx(char* lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
4545
static extern PInvoke.User32.LoadString(System.IntPtr hInstance, uint uID, char* lpBuffer, int cchBufferMax) -> int
4646
static extern PInvoke.User32.UnregisterClass(string lpClassName, System.IntPtr hInstance) -> bool
47-
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED -> System.IntPtr
47+
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED -> System.IntPtr
48+
static PInvoke.User32.GetLastInputInfo(System.IntPtr plii) -> bool
49+
static PInvoke.User32.GetLastInputInfo(out PInvoke.User32.LASTINPUTINFO plii) -> bool
50+
static extern PInvoke.User32.GetLastInputInfo(PInvoke.User32.LASTINPUTINFO* plii) -> bool
51+
PInvoke.User32.LASTINPUTINFO
52+
PInvoke.User32.LASTINPUTINFO.LASTINPUTINFO() -> void
53+
PInvoke.User32.LASTINPUTINFO.cbSize -> int
54+
PInvoke.User32.LASTINPUTINFO.dwTime -> uint
55+
static PInvoke.User32.LASTINPUTINFO.Create() -> PInvoke.User32.LASTINPUTINFO

src/User32/User32+LASTINPUTINFO.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright © .NET Foundation and Contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace PInvoke
5+
{
6+
using System;
7+
using System.Runtime.InteropServices;
8+
9+
/// <content>
10+
/// Contains the <see cref="LASTINPUTINFO"/> nested type.
11+
/// </content>
12+
public partial class User32
13+
{
14+
/// <summary>
15+
/// Contains the time of the last input. It is used with the <see cref="GetLastInputInfo(LASTINPUTINFO*)"/> function.
16+
/// </summary>
17+
public struct LASTINPUTINFO
18+
{
19+
/// <summary>
20+
/// The size of the structure, in bytes. This member must be set to <c>sizeof(LASTINPUTINFO)</c>.
21+
/// </summary>
22+
public int cbSize;
23+
24+
/// <summary>
25+
/// The tick count when the last input event was received.
26+
/// </summary>
27+
public uint dwTime;
28+
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="LASTINPUTINFO"/> struct.
31+
/// </summary>
32+
/// <returns>An initialized instance of the struct.</returns>
33+
public static unsafe LASTINPUTINFO Create() => new LASTINPUTINFO { cbSize = sizeof(LASTINPUTINFO) };
34+
}
35+
}
36+
}

src/User32/User32.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,6 +3944,27 @@ public static unsafe extern uint MsgWaitForMultipleObjectsEx(
39443944
WakeMask dwWakeMask,
39453945
MsgWaitForMultipleObjectsExFlags dwFlags);
39463946

3947+
/// <summary>
3948+
/// Retrieves the time of the last input event.
3949+
/// </summary>
3950+
/// <param name="plii">A pointer to a <see cref="LASTINPUTINFO"/> structure that receives the time of the last input event.</param>
3951+
/// <returns>
3952+
/// If the function succeeds, the return value is nonzero.
3953+
/// If the function fails, the return value is zero.
3954+
/// </returns>
3955+
/// <remarks>
3956+
/// This function is useful for input idle detection. However, GetLastInputInfo does not provide system-wide
3957+
/// user input information across all running sessions. Rather, GetLastInputInfo provides session-specific user input
3958+
/// information for only the session that invoked the function.
3959+
/// The tick count when the last input event was received (see <see cref="LASTINPUTINFO"/>) is not guaranteed to be incremental.
3960+
/// In some cases, the value might be less than the tick count of a prior event. For example, this can be caused by
3961+
/// a timing gap between the raw input thread and the desktop thread or an event raised by SendInput, which supplies its own tick count.
3962+
/// </remarks>
3963+
[DllImport(nameof(User32))]
3964+
[return: MarshalAs(UnmanagedType.Bool)]
3965+
public static extern unsafe bool GetLastInputInfo(
3966+
[Friendly(FriendlyFlags.Out)] LASTINPUTINFO* plii);
3967+
39473968
/// <summary>
39483969
/// The BeginPaint function prepares the specified window for painting and fills a <see cref="PAINTSTRUCT"/> structure with information about the painting.
39493970
/// </summary>

0 commit comments

Comments
 (0)