RefocusGuard

版本 v0.1.3·更新於 2026-09-23

Consumes refocus mouse input and blocks local attack/placement gameplay endpoints until the activation click is safely released.

模組介紹 作者原文

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 Block or BuildMenu.
  • Middle mouse cannot trigger SecondaryAttack or Remove.
  • Matching raw ZInput mouse-button reads are also suppressed.
  • Player.PlayerAttackInput is skipped during the refocus guard.
  • Player.UpdatePlacement is skipped during the refocus guard.
  • Humanoid.StartAttack has 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.

安裝與使用 安裝:BepInEx 外掛

  1. 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
  2. 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
  3. 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
  4. 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。

帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。 多人連線時,主機與所有用戶端需要安裝一致的模組。

前置依賴

下面這些內容需要先安裝,否則該模組不會生效:

denikson-BepInExPack_Valheim

檔案與校驗

檔案名稱
RefocusGuard-0.1.3.zip
檔案大小
21.3 KiB