-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathotherKeys.lua
More file actions
77 lines (69 loc) · 2.28 KB
/
Copy pathotherKeys.lua
File metadata and controls
77 lines (69 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local RunService = game:GetService("RunService");
local UserInputService = game:GetService("UserInputService");
local movingPart = workspace.player.playerHitbox;
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local bindables = ReplicatedStorage.LocalBindables
local shiftPressed = bindables.shiftPressed
local shiftReleased = bindables.shiftReleased
local backspacePressed = bindables.backspacePressed
local backspaceReleased = bindables.backspaceReleased
local spacePressed = bindables.spacePressed
local spaceReleased = bindables.spaceReleased
local xPressed = bindables.xPressed
local xReleased = bindables.xReleased
local keyCodeToIsPressedMap = {
[Enum.KeyCode.LeftShift] = false,
[Enum.KeyCode.Space] = false,
[Enum.KeyCode.X] = false,
[Enum.KeyCode.Tab] = false,
[Enum.KeyCode.RightShift] = false,
};
local function isRelevantInput(input)
return (
input.KeyCode == Enum.KeyCode.LeftShift
or input.KeyCode == Enum.KeyCode.RightShift
or input.KeyCode == Enum.KeyCode.Space
or input.KeyCode == Enum.KeyCode.X
or input.KeyCode == Enum.KeyCode.Backspace
);
end
local function registerKeyPressed(input, gameProcessedEvent)
if gameProcessedEvent or not isRelevantInput(input) then
return;
end
if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
--_G.shiftMultiplier = 0.5
shiftPressed:Fire()
end
if input.KeyCode == Enum.KeyCode.Space then
spacePressed:Fire()
end
if input.KeyCode == Enum.KeyCode.X then
xPressed:Fire()
end
if input.KeyCode == Enum.KeyCode.Backspace then
backspacePressed:Fire()
end
keyCodeToIsPressedMap[input.KeyCode] = true;
end
local function unregisterKeyPressed(input, gameProcessedEvent)
if gameProcessedEvent or not isRelevantInput(input) then
return;
end
if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
--_G.shiftMultiplier = 1
shiftReleased:Fire()
end
if input.KeyCode == Enum.KeyCode.Space then
spaceReleased:Fire()
end
if input.KeyCode == Enum.KeyCode.X then
xReleased:Fire()
end
if input.KeyCode == Enum.KeyCode.Backspace then
backspaceReleased:Fire()
end
keyCodeToIsPressedMap[input.KeyCode] = false;
end
UserInputService.InputBegan:Connect(registerKeyPressed);
UserInputService.InputEnded:Connect(unregisterKeyPressed);