慣性聚合 高效追蹤和閱讀你感興趣的部落格、新聞、科技資訊
閱讀原文 在慣性聚合中打開

推薦訂閱源

Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
博客园 - 叶小钗
MyScale Blog
MyScale Blog
V
Visual Studio Blog
月光博客
月光博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
I
InfoQ
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志
Jina AI
Jina AI
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Blog — PlanetScale
Blog — PlanetScale
Last Week in AI
Last Week in AI
雷峰网
雷峰网
Stack Overflow Blog
Stack Overflow Blog
博客园 - Franky

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python)
建立 GamepadTester:開發者對於在瀏覽器中讀取控制器輸入的觀點
Raxa · 2026-05-24 · via DEV Community

從開發者的角度來看,創建一個遊戲桿測試器不僅僅是模擬按鍵壓下 — 它是關於理解硬體如何與軟體實時溝通。現代瀏覽器透過遊戲桿 API 提供對控制器數據的直接訪問,使得僅使用 JavaScript、HTML 和 CSS 就能構建一個功能完整的遊戲桿測試器。

任何基於瀏覽器的遊戲桿測試工具的核心始於 navigator.getGamepads() 方法。這個 API 允許開發者訪問已連接的控制器並獲取它們的按鍵狀態、軸值和元數據。

一個簡單的連接監聽器看起來像這樣:

JavaScript

window.addEventListener("gamepadconnected", (event) => {
console.log("控制器已連接:", event.gamepad.id);
});
連接後,控制器的狀態並不會自動推送到您的應用程式。相反地,您必須使用 requestAnimationFrame() 持續掃描它以捕捉實時更新。

JavaScript

function update() {
const gamepads = navigator.getGamepads();
const gp = gamepads[0];

if (gp) {
gp.buttons.forEach((button, index) => {
console.log(Button ${index}:, button.pressed);
});

gp.axes.forEach((axis, index) => {
  console.log(`Axis ${index}:`, axis.toFixed(2));
});

Enter fullscreen mode Exit fullscreen mode

}

requestAnimationFrame(update);
}

update();
這個迴圈構成了任何響應式
網頁基礎遊戲桿測試工具的骨幹,確保視覺更新順暢而不阻礙UI執行緒.

處理軸與靜區域
建立控制器測試介面時的一大挑戰是處理搖桿雜訊。軸值通常範圍在 -1 到 1 之間,但靜止值很少是完美的零。小的波動需要實現一個靜區來避免偽裝移動偵測.

一個常見的方法:

JavaScript

function applyDeadZone(value, threshold = 0.05) {
return Math.abs(value) < 閾值 ? 0 : value;
}
這增進了穩定性並模擬了許多商業遊戲如何處理搖桿輸入.

可視化輸入數據
一個完整的遊戲手柄測試者不夠夠沒有視覺反饋。開發者通常:

使用 CSS 變換將軸值映射到搖桿位置元素
按下時動態高亮按鈕
顯示原始數值數據以進行精確度測試
記錄掃描時間戳以進行延遲分析
例如,將軸映射到視覺搖桿:

JavaScript

stickElement.style.transform =
translate(${axisX * 50}px, ${axisY * 50}px);
這將標準化軸數據轉換為螢幕上的像素移動。

檢查頻率和性能考量
雖然 Gamepad API 沒有直接暴露檢查頻率,但開發者可以通過測量幀更新之間的時間差來估計它。然而,請記住瀏覽器刷新率和系統性能會影響這些計算。

優化渲染效能至關重要。避免在迴圈內進行繁重的 DOM 更新。相反地,請批量處理 UI 變更或使用輕量級的 canvas 渲染以獲得更順滑的動畫效果.

跨瀏覽器相容性挑戰
並非所有瀏覽器都相同地處理控制器。差異可能包括:

按鈕索引對應
觸發軸行為(按鈕與軸混合)
藍牙延遲變化
廠商特定控制器ID
在Chrome、Edge和Firefox上進行測試可確保任何嚴肅的gamepadtester網應用程式的更廣泛的兼容性

為何開發者應該建立一個
建立一個控制器測試工具是一個極好的練習:

實時輸入處理
硬體軟體互動
性能優化
使用者介面響應速度
它連結前端開發與底層設備輸入概念——這在典型的網頁專案中很少被探討。

最終來說,建立自己的測試平台能加深您對互動系統的理解。一個設計良好的遊戲桿測試工具不僅僅是一個實用工具 — 它是正確實現實時網頁工程的展覽。