{"id":"hooskyfivem/inputcontexthandler","name":"inputcontexthandler","scope":"hooskyfivem","platform":"roblox","description":"Code-first wrapper over the Roblox Input Action System, with declarative context schemas and a context stack","version":"0.1.0","latest":"0.1.0","versions":["0.1.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"5d2fd79a49ada809d5f41f4fb1d3994110abbd8ad77210995ab15c678a44da3f","likes":0,"downloads":0,"install":"forest install hooskyfivem/inputcontexthandler","url":"https://forest.dev/p/roblox/hooskyfivem/inputcontexthandler","files":"https://api.forest.dev/ai/package/roblox/hooskyfivem/inputcontexthandler/files","readme":"## Install\n\n```toml\n[dependencies]\nInputContextHandler = \"hooskyfivem/inputcontexthandler@0.1.0\"\n```\n\n## Declarative\n\nDescribe a context as a table. Actions and bindings are created for you.\n\n```luau\nlocal ICH = require(ReplicatedStorage.Packages.InputContextHandler)\n\nlocal Build = ICH.new(\"Build\", {\n\tPriority = 2000,\n\tSink = true,\n\tActions = {\n\t\tPlace = { Enum.KeyCode.MouseButton1, Enum.KeyCode.ButtonR2 },\n\t\tRotate = { Enum.KeyCode.R, Enum.KeyCode.ButtonY },\n\t\tCancel = { Enum.KeyCode.Q, Enum.KeyCode.ButtonB },\n\t\tToggleView = { Enum.KeyCode.V, Enum.KeyCode.ButtonL3 },\n\n\t\tPan = { Type = \"Direction2D\", Bindings = { \"WASD\", \"Thumbstick1\" } },\n\t\tZoom = { Type = \"Direction1D\", Bindings = { { Positive = Enum.KeyCode.E, Negative = Enum.KeyCode.Q } } },\n\t},\n})\n\nBuild:On(\"Place\", function()\n\tprint(\"place\")\nend)\n\nBuild:On(\"Rotate\", function()\n\tprint(\"rotate\")\nend)\n```\n\nAn action written as a bare array (`Place = { ... }`) is a `Bool` action bound to each entry.\nUse the long form when you need a type or per-binding options.\n\n## Fluent\n\n```luau\nlocal Gameplay = ICH.new(\"Gameplay\")\n\nGameplay:Action(\"Jump\")\n\t:Bind(Enum.KeyCode.Space)\n\t:Bind(Enum.KeyCode.ButtonA)\n\t:OnPressed(function()\n\t\tprint(\"jump\")\n\tend)\n```\n\n## The context stack\n\nThe reason this exists: entering a mode should suspend the mode underneath it, and leaving\nshould restore it — without every system tracking who else is listening.\n\n```luau\nICH.Push(Build)   --// Gameplay is disabled, Build takes priority\nICH.Pop()         --// Build is disabled, Gameplay is restored\n```\n\n`Push` raises the context's `Priority` above whatever it covers, so `Sink = true` reliably\nswallows input from the layer below. `Remove(context)` pulls a context out from the middle\nof the stack without disturbing the rest.\n\n## Devices\n\n```luau\nICH.Device.Current        --// \"Keyboard\" | \"Gamepad\" | \"Touch\"\nICH.Device.IsGamepad()\nICH.Device.Changed:Connect(function(current, previous)\n\t--// swap button prompts\nend)\n```\n\nTouch bindings take a `GuiButton` — pass the instance and the action fires from that button:\n\n```luau\nBuild:Get(\"Place\"):Bind(PlaceButton)\n```\n\n## Reading state\n\n```luau\nBuild:Value(\"Pan\")       --// Vector2 for a Direction2D action\nBuild:IsPressed(\"Place\")\nBuild:Get(\"Zoom\"):GetValue()\n```\n\n## Rebinding\n\n```luau\nBuild:Get(\"Rotate\"):Bind(Enum.KeyCode.R, \"Primary\")\nBuild:Get(\"Rotate\"):Rebind(\"Primary\", Enum.KeyCode.T)\n```\n\n## API\n\n**Module** — `new(name, schema?)`, `Get(name)`, `Destroy(name)`, `Push(context)`, `Pop()`,\n`Remove(context)`, `Current()`, `Clear()`, `Device`, `Presets`, `ContextPushed`,\n`ContextPopped`.\n\n**Context** — `Action(name, kind?)`, `Get`, `Expect`, `Remove`, `Apply(schema)`, `On`,\n`OnReleased`, `OnChanged`, `Value`, `IsPressed`, `Enable`, `Disable`, `SetEnabled`,\n`IsEnabled`, `Destroy`. Unknown fields pass through to the underlying `InputContext`.\n\n**Action** — `Bind(schema, name?)`, `BindMany`, `GetBinding`, `Rebind`, `ClearBindings`,\n`OnPressed`, `OnReleased`, `OnChanged`, `GetValue`, `IsPressed`, `Fire`, `SetEnabled`,\n`Destroy`.\n\n**Binding** — `SetKeyCode`, `SetUIButton`, `SetScale`, `SetVector2Scale`, `SetThresholds`,\n`SetPreset`, `Apply`, `Destroy`.\n\n**Presets** — `WASD`, `ArrowKeys`, `DPad`, `Thumbstick1`, `Thumbstick2`, `MouseWheel`.\n\nAction kinds are `\"Bool\"`, `\"Direction1D\"`, `\"Direction2D\"`, `\"Direction3D\"`.","readmeTruncated":false}