HotkeyToggle runs a background Win32 thread that polls keyboard state every 25 milliseconds. When the combination Ctrl+Shift+P is detected, it callsDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/angelballay/pes6_game_physics_mod/llms.txt
Use this file to discover all available pages before exploring further.
TogglePhysicsModEnabled() and, if Kitserver is available, triggers the on-screen overlay message to display the new state. The polling thread starts after both hooks are successfully installed and runs until DLL unload.
Public API
StartHotkeyToggle
g_hotkeyRunning = true and calls CreateThread to start HotkeyThreadProc. Called from MainThread in dllmain.cpp after InstallContextHook, InstallPowerHook, and the optional Kitserver overlay are all set up.
If CreateThread succeeds, the returned handle is immediately closed with CloseHandle and the local handle variable is set to nullptr. The thread continues running — handle closure only releases the kernel handle resource, not the thread itself. If CreateThread fails, g_hotkeyRunning is reset to false and an error is written to the log.
If StartHotkeyToggle is called again while the thread is already running, the guard if (g_hotkeyRunning) return; prevents a second thread from being created.
StopHotkeyToggle
g_hotkeyRunning = false. The polling thread checks this flag at the top of each 25 ms iteration and exits its loop naturally, logging "[HOTKEY] Thread finalizado." before returning. Called from the DLL_PROCESS_DETACH branch of DllMain.
Polling Logic
The thread functionHotkeyThreadProc uses two helper predicates:
IsKeyDown checks the high-order bit of GetAsyncKeyState — true while the key is physically held. WasKeyPressedNow checks the low-order bit — true only on the leading edge of a key press (set when the key transitions from up to down since the last call for this thread).
The toggle fires when VK_CONTROL and VK_SHIFT are held and 'P' has a leading-edge transition. Using WasKeyPressedNow for P means the toggle fires exactly once per press regardless of how long P is held.
Full Thread Implementation
Sleep(25) call at the end of each loop iteration gives the thread a 40 Hz polling rate. This is more than sufficient for human key detection latency while keeping CPU usage negligible.
The thread handle returned by
CreateThread is closed immediately after creation with CloseHandle. This is intentional and correct Win32 practice. Closing the handle does not terminate the thread — it only releases the caller’s reference to the kernel thread object. The thread continues executing HotkeyThreadProc until g_hotkeyRunning becomes false.