Would it be possible to make an ingame "key logger" of sotrs?

“Hotkey logger a roblox script to log player movements hotkeys pressed, including the time they were pressed with the data sent to a webhook.”
HTTPS requesta are on and I find the script challenging to work with for my ingame moderation; I do not like how number 1, the data is not being sent to said webhook (not included for obvious reasons) 2, I cannot confirm which player presses which key. I want it so if player 1 presses A key, and player 2 presses A key, lets say theres a coincedence and they press it at the same time. I want to tell them apart via username. I’ve worked with scripts sending data via roblox to webhook and this is the first time I’ve really had challenges with it. Feedback and tweaks to code appreciated

-- Hotkey Logger: A Roblox script to log player movements and hotkeys pressed, including timestamps, to a webhook.

local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local webhookURL = "YOUR_WEBHOOK_URL_HERE"

local function sendLog(message)
    local payload = HttpService:JSONEncode({content = message})
    HttpService:PostAsync(webhookURL, payload, Enum.HttpContentType.ApplicationJson)
end

local function logMovement(player, key)
    local timestamp = os.date("%Y-%m-%d %H:%M:%S")
    local message = player.Name .. " pressed " .. key .. " at " .. timestamp
    sendLog(message)
end

Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        if message:lower() == "/logkeys" then
            local character = player.Character or player.CharacterAdded:Wait()
            local humanoid = character:WaitForChild("Humanoid")
            local playerInput = game:GetService("UserInputService")

            playerInput.InputBegan:Connect(function(input, gameProcessed)
                if not gameProcessed then
                    logMovement(player, input.KeyCode.Name)
                end
            end)
        end
    end)
end)

HTTPService limits should be accounted for

Yes, it’s possible. No, you cannot do it securely.

In the end, you would have to send inputs from the client to the server as you cannot get inputs of a client from the server.

Discord banned Roblox requests, use a proxy.

i probably wouldn’t try logging keys since you can’t trust the client and it has privacy implications; instead i’d log the state of the player’s character into a buffer and send it to the server
here’s a module i made as an example:

--!strict
--!optimize 2
--!native
local BufferUtils = {}

--writes a cframe to a buffer (48 bytes)
function BufferUtils.writeCFrame(b:buffer, offset:number, cf:CFrame): ()
	assert(typeof(cf) == 'CFrame' and buffer.len(b) - offset >= 48)
	for i,v in {cf:GetComponents()} do
		buffer.writef32(b, offset + ((i - 1) * 4), v)
	end
end

--reads 48 bytes from a buffer as a cframe and returns it
function BufferUtils.readCFrame(b:buffer, offset:number): CFrame
	assert(buffer.len(b) - offset >= 48)
	local components:{[number]:number} = table.create(12)
	for i = 0, 11 do
		components[i + 1] = buffer.readf32(b, offset + (i * 4))
	end
	return CFrame.new(unpack(components))
end

--writes a vector3 to a buffer (12 bytes)
function BufferUtils.writeVector(b:buffer, offset:number, vector:Vector3): ()
	assert(type(vector) == 'vector' and buffer.len(b) - offset >= 12)
	buffer.writef32(b, offset, vector.X)
	buffer.writef32(b, offset + 4, vector.Y)
	buffer.writef32(b, offset + 8, vector.Z)
end

--reads 12 bytes from a buffer as a vector3 and returns it
function BufferUtils.readVector(b:buffer, offset:number): Vector3
	assert(buffer.len(b) - offset >= 12)
	return Vector3.new(
		buffer.readf32(b, offset),
		buffer.readf32(b, offset + 4),
		buffer.readf32(b, offset + 8)
	)
end

return BufferUtils

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.