-- Compiled with roblox-ts v3.0.0 -- Internal --* Binds every window's `hotkey` through one InputContext under `parent`. Returns a cleanup function. local function attachHotkeys(rules, controls, parent) local context = Instance.new("InputContext") context.Name = "ForgeHotkeys" local newAction = function(actionName, key) local action = Instance.new("InputAction") action.Name = actionName action.Type = Enum.InputActionType.Bool local binding = Instance.new("InputBinding") binding.KeyCode = key binding.Parent = action action.Parent = context return action end -- One always-on context; modifier state is tracked here. -- (Toggling InputContext.Enabled drops inputs — engine bug.) local held = {} local tracked = {} local trackModifier = function(key) local _key = key if tracked[_key] ~= nil then return nil end local _key_1 = key tracked[_key_1] = true local action = newAction(`modifier:{key.Name}`, key) action.Pressed:Connect(function() local _key_2 = key held[_key_2] = true return held end) action.Released:Connect(function() local _key_2 = key -- ▼ Set.delete ▼ local _valueExisted = held[_key_2] ~= nil held[_key_2] = nil -- ▲ Set.delete ▲ return _valueExisted end) end for name, def in pairs(rules) do if def.hotkey == nil then continue end local _hotkey = def.hotkey local binds = if typeof(_hotkey) == "EnumItem" then { def.hotkey } elseif def.hotkey.hold ~= nil then { def.hotkey } else (def.hotkey) local trigger = function() if controls.isOpen(name) then controls.close(name) else controls.open(name) end end -- ▼ ReadonlyArray.forEach ▼ local _callback = function(bind, index) local _bind = bind if typeof(_bind) == "EnumItem" then newAction(`{name}:{index}`, bind).Pressed:Connect(function() if next(held) == nil then trigger() end end) else local hold = bind.hold trackModifier(hold) newAction(`{name}:{index}`, bind.press).Pressed:Connect(function() if held[hold] ~= nil then trigger() end end) end end for _k, _v in binds do _callback(_v, _k - 1, binds) end -- ▲ ReadonlyArray.forEach ▲ end context.Parent = parent return function() return context:Destroy() end end return { default = attachHotkeys, }