Recording Key presses and saving them

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?

1 Like

Wym by this line? can you explain this line in detail please.

image

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)
1 Like

It calculates the time between each key that has been pressed.

For example, I press E, and then it waits until i press another key, example F, it calculates how long it took to press the next key.

Similar to that, yes.

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.

1 Like

Seems a bit complicated, I’ll try to make the script and let you know!

1 Like

Alrighty, thanks.

I will continue to explain further if needed.

image
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)

Exactly like that, yeah.

Now I need to figure out the actual recording thing.

Now you can just save the recording, transfer the keys table to the server and save it with datastore.

Alright, thanks for the help, I’ll let you know if I need anything more.

1 Like