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

Commit

Permalink
Merge pull request #542 from NotCoffee418/GetLastInputInfo
Browse files Browse the repository at this point in the history
Add User32.GetLastInputInfo
  • Loading branch information
AArnott authored Nov 27, 2020
2 parents f9ae958 + ac44163 commit 395b66d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/User32/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ static extern PInvoke.User32.EnumDisplaySettings(char* lpszDeviceName, uint iMod
static extern PInvoke.User32.EnumDisplaySettingsEx(char* lpszDeviceName, uint iModeNum, PInvoke.DEVMODE* lpDevMode, PInvoke.User32.EnumDisplaySettingsExFlags dwFlags) -> bool
static extern PInvoke.User32.LoadString(System.IntPtr hInstance, uint uID, char* lpBuffer, int cchBufferMax) -> int
static extern PInvoke.User32.UnregisterClass(string lpClassName, System.IntPtr hInstance) -> bool
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED -> System.IntPtr
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED -> System.IntPtr
static PInvoke.User32.GetLastInputInfo(System.IntPtr plii) -> bool
static PInvoke.User32.GetLastInputInfo(out PInvoke.User32.LASTINPUTINFO plii) -> bool
static extern PInvoke.User32.GetLastInputInfo(PInvoke.User32.LASTINPUTINFO* plii) -> bool
PInvoke.User32.LASTINPUTINFO
PInvoke.User32.LASTINPUTINFO.LASTINPUTINFO() -> void
PInvoke.User32.LASTINPUTINFO.cbSize -> int
PInvoke.User32.LASTINPUTINFO.dwTime -> uint
static PInvoke.User32.LASTINPUTINFO.Create() -> PInvoke.User32.LASTINPUTINFO
36 changes: 36 additions & 0 deletions src/User32/User32+LASTINPUTINFO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright © .NET Foundation and Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace PInvoke
{
using System;
using System.Runtime.InteropServices;

/// <content>
/// Contains the <see cref="LASTINPUTINFO"/> nested type.
/// </content>
public partial class User32
{
/// <summary>
/// Contains the time of the last input. It is used with the <see cref="GetLastInputInfo(LASTINPUTINFO*)"/> function.
/// </summary>
public struct LASTINPUTINFO
{
/// <summary>
/// The size of the structure, in bytes. This member must be set to <c>sizeof(LASTINPUTINFO)</c>.
/// </summary>
public int cbSize;

/// <summary>
/// The tick count when the last input event was received.
/// </summary>
public uint dwTime;

/// <summary>
/// Initializes a new instance of the <see cref="LASTINPUTINFO"/> struct.
/// </summary>
/// <returns>An initialized instance of the struct.</returns>
public static unsafe LASTINPUTINFO Create() => new LASTINPUTINFO { cbSize = sizeof(LASTINPUTINFO) };
}
}
}
21 changes: 21 additions & 0 deletions src/User32/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3944,6 +3944,27 @@ public static unsafe extern uint MsgWaitForMultipleObjectsEx(
WakeMask dwWakeMask,
MsgWaitForMultipleObjectsExFlags dwFlags);

/// <summary>
/// Retrieves the time of the last input event.
/// </summary>
/// <param name="plii">A pointer to a <see cref="LASTINPUTINFO"/> structure that receives the time of the last input event.</param>
/// <returns>
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
/// </returns>
/// <remarks>
/// This function is useful for input idle detection. However, GetLastInputInfo does not provide system-wide
/// user input information across all running sessions. Rather, GetLastInputInfo provides session-specific user input
/// information for only the session that invoked the function.
/// The tick count when the last input event was received (see <see cref="LASTINPUTINFO"/>) is not guaranteed to be incremental.
/// In some cases, the value might be less than the tick count of a prior event. For example, this can be caused by
/// a timing gap between the raw input thread and the desktop thread or an event raised by SendInput, which supplies its own tick count.
/// </remarks>
[DllImport(nameof(User32))]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern unsafe bool GetLastInputInfo(
[Friendly(FriendlyFlags.Out)] LASTINPUTINFO* plii);

/// <summary>
/// The BeginPaint function prepares the specified window for painting and fills a <see cref="PAINTSTRUCT"/> structure with information about the painting.
/// </summary>
Expand Down

0 comments on commit 395b66d

Please sign in to comment.