# Idle detection


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Windows API binding

------------------------------------------------------------------------

<a
href="https://github.com/sayanbanerjee32/snooper_pkg/blob/main/snooper_pkg/idle_detector.py#L26"
target="_blank" style="float:right; font-size:smaller">source</a>

### LASTINPUTINFO

``` python
def LASTINPUTINFO(
    *args, **kwargs
):
```

*ctypes representation of the Windows
[`LASTINPUTINFO`](https://sayanbanerjee32.github.io/snooper_pkg/idle_detector.html#lastinputinfo)
structure.*

<details open class="code-fold">
<summary>Exported source</summary>

``` python
class LASTINPUTINFO(ctypes.Structure):
    "ctypes representation of the Windows `LASTINPUTINFO` structure."

    _fields_ = [
        ("cbSize", wintypes.UINT),   # Size of this structure in bytes
        ("dwTime", wintypes.DWORD),  # Tick count when the last input occurred
    ]
```

</details>

## Idle-time queries

------------------------------------------------------------------------

<a
href="https://github.com/sayanbanerjee32/snooper_pkg/blob/main/snooper_pkg/idle_detector.py#L36"
target="_blank" style="float:right; font-size:smaller">source</a>

### get_last_input_tick

``` python
def get_last_input_tick():
```

*Call `GetLastInputInfo` and return its last-input tick count in
milliseconds.*

------------------------------------------------------------------------

<a
href="https://github.com/sayanbanerjee32/snooper_pkg/blob/main/snooper_pkg/idle_detector.py#L49"
target="_blank" style="float:right; font-size:smaller">source</a>

### get_idle_seconds

``` python
def get_idle_seconds():
```

*Return the elapsed seconds between system uptime and the last input
tick.*

- `GetLastInputInfo` returns a success flag, but the value assigned to
  `ok` is not checked. If the API call fails,
  [`get_last_input_tick()`](https://sayanbanerjee32.github.io/snooper_pkg/idle_detector.html#get_last_input_tick)
  may return an unchanged or initial `info.dwTime` value.

- `GetTickCount64()` returns a 64-bit tick count, while
  `LASTINPUTINFO.dwTime` is a 32-bit `DWORD`. The last-input count wraps
  after approximately 49.7 days of uptime, so the direct subtraction may
  eventually produce an incorrect idle duration.

- The module-level `info` structure is mutated on every API call.
  Confirm whether concurrent calls are possible and whether the shared
  buffer needs synchronization or per-call allocation.
