Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IsKeyDown and AreKeysDown Processed Event #90

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
Update Keyboard.lua
LuaRook authored May 17, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit d2f6bace3345f1fbd1e5f53d0b270102c16a9ce3
10 changes: 5 additions & 5 deletions modules/input/Keyboard.lua
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ local UserInputService = game:GetService("UserInputService")
The Keyboard class is part of the Input package.

```lua
local Keyboard = require(packages.Input).Keyboard
local Keyboard = require(packages.Input.Keyboard)
```
]=]
local Keyboard = {}
@@ -60,7 +60,7 @@ function Keyboard.new()
self._trove = Trove.new()
self.KeyDown = self._trove:Construct(Signal)
self.KeyUp = self._trove:Construct(Signal)
self.KeysDown = {}
self.State = {}
self:_setup()
return self
end
@@ -75,7 +75,7 @@ end
```
]=]
function Keyboard:IsKeyDown(keyCode: Enum.KeyCode): boolean
return self.KeysDown[keyCode] ~= nil
return self.State[Keyboard] == true
end


@@ -113,15 +113,15 @@ function Keyboard:_setup()
self._trove:Connect(UserInputService.InputBegan, function(input, processed)
if processed then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
self.KeysDown[input.KeyCode] = true
self.State[input.KeyCode] = true
self.KeyDown:Fire(input.KeyCode)
end
end)

self._trove:Connect(UserInputService.InputEnded, function(input, processed)
if processed then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
self.KeysDown[input.KeyCode] = nil
self.State[input.KeyCode] = nil
self.KeyUp:Fire(input.KeyCode)
end
end)