Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
RefocusGuard
Consumes refocus mouse input and blocks local attack/placement gameplay endpoints until the activation click is safely released.
By Daishi11
| Last updated | 2 weeks ago |
| Total downloads | 41 |
| Total rating | 0 |
| Categories | Mods Tweaks AI Generated |
| Dependency string | Daishi11-RefocusGuard-0.1.3 |
| Dependants | 0 other packages depend on this package |
This mod requires the following mods to function
denikson-BepInExPack_Valheim
BepInEx pack for Valheim. Preconfigured with the correct entry point for mods and preferred defaults for the community.
Preferred version: 5.4.2350README
Refocus Guard
A tiny client-side Valheim mod for one annoyance:
When Valheim regains input focus after Alt-Tab, the mouse click used to activate the game is consumed instead of becoming an in-game action.
What is protected
While the activation click is being consumed:
- Left mouse cannot trigger
Attack. - Right mouse cannot trigger
BlockorBuildMenu. - Middle mouse cannot trigger
SecondaryAttackorRemove. - Matching raw ZInput mouse-button reads are also suppressed.
Player.PlayerAttackInputis skipped during the refocus guard.Player.UpdatePlacementis skipped during the refocus guard.Humanoid.StartAttackhas a local-player safety net during the guard.
Once the pressed activation button is released, controls return to normal immediately.
Why there is a short safety window
Unity can expose focus gain and the activation mouse edge in an awkward order inside the same frame. Refocus Guard therefore suppresses the three mouse buttons for 0.15 seconds after refocus, latches any activation button that is actually held, and keeps only that held button suppressed until release.
A highest-priority Player.Update prefix is also used so the guard is armed before Valheim reads Attack/Block/SecondaryAttack in the first focused frame.
Normal focus/input events are intentionally not logged; only the startup message is emitted during ordinary operation.
What it does not do
Refocus Guard does not force the Windows foreground window to accept keyboard or mouse input. Windows may occasionally bring Valheim to the foreground without giving it full input focus until you click the window.
That activation click is exactly what this mod makes safe.
The mod does not:
- modify attacks or combat after refocus is complete,
- change keybinds,
- add config,
- add prefabs/items/RPCs/save data,
- require installation on the server.
Test
- Start Valheim and enter a world.
- Equip a weapon or tool.
- Alt-Tab to another application.
- Click Valheim with left mouse.
- The game should regain focus without attacking or swinging the tool.
- Release left mouse, then click normally; the attack should work immediately.
- Repeat with right mouse; it should not block/open the build menu from the activation click.
- Repeat with middle mouse while holding a hammer; it should not remove a piece from the activation click.
- Alt-Tab back using only the keyboard. Normal mouse input should work after the tiny two-frame focus grace period.