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

Add User32.GetLastInputInfo #542

Merged
merged 2 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/User32/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ 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 extern PInvoke.User32.GetLastInputInfo(ref 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
41 changes: 41 additions & 0 deletions src/User32/User32+LASTINPUTINFO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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"/> 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 LASTINPUTINFO Create()
{
var nw = default(LASTINPUTINFO);
nw.cbSize = Marshal.SizeOf(typeof(LASTINPUTINFO));
return nw;
}
AArnott marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
20 changes: 20 additions & 0 deletions src/User32/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3944,6 +3944,26 @@ 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), SetLastError = true, EntryPoint = "GetLastInputInfo")]
AArnott marked this conversation as resolved.
Show resolved Hide resolved
AArnott marked this conversation as resolved.
Show resolved Hide resolved
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
AArnott marked this conversation as resolved.
Show resolved Hide resolved

/// <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