Is it possible to record key presses by the client with UserInputService?
I need this for a timecoding cue.
The user (client) starts recording the key presses, presses absolutely any key, the script also calculates the time needed until another key has been pressed.
After done with recording, the recording can be played and saved to a datastore.
Reason I need this is for timecoding an array of 24 moving heads, instead of controlling them manually.
If something is not clear, I will explain it again.
Is this possible or not?
This is what i've achieved (lmk if you meant something else)
local uis = game:GetService("UserInputService")
local keys = {}
uis.InputBegan:Connect(function(obj) -- When an input detected
if obj.UserInputType == Enum.UserInputType.Keyboard then -- If input type is a keyboard
table.insert(keys,{Key = obj.KeyCode.Name, Time = tick()}) -- inserts key and time when its pressed in keys table
end
end)
script.Parent.TextButton.MouseButton1Click:Connect(function() -- when button clicked on ui
for i,v in pairs(keys) do -- gets every key and time from the keys table
print(v.Key.." pressed "..math.floor(tick()-v.Time).." seconds ago.") -- debugs (prints)
end
end)
Just I need to have a script that records the key presses, and can be played. While the keys are being pressed, functions fire (I already have all those functions that need to be fired, and all the keys assigned to functions, all thats needed is a script to record the key presses).
The recording gets saved and the user can play the recording. (Shown in F9 console which key gets pressed).
My explainations are not the best at all, It seems like I have a hard time explaining it properly here.
Like this?
I pressed A key then i wait 4 seconds then i pressed B
After the B key i waited 2 seconds then i pressed C key.
and so on.
Code
local uis = game:GetService("UserInputService")
local keys = {}
uis.InputBegan:Connect(function(obj)
if obj.UserInputType == Enum.UserInputType.Keyboard then
table.insert(keys,{Key = obj.KeyCode.Name, Time = tick()})
end
end)
script.Parent.TextButton.MouseButton1Click:Connect(function()
for i,v in pairs(keys) do
if i == 1 then
print(v.Key.." pressed "..math.floor(tick()-v.Time).." seconds ago.")
else
print(v.Key.." pressed after "..math.floor(v.Time-keys[i-1].Time).." seconds of "..keys[i-1].Key)
end
end
end)