Page 1 of 1

onPlayerKeyPress problem

Posted: September 7th, 2018, 2:29 pm
by wbty
Hi,
I need a little help with this, does anyone know correct way to detect player keys?
I already made something but I got error

Code: Select all

Event onPlayerKeyPress: attempt to call a number value

Re: onPlayerKeyPress problem

Posted: September 7th, 2018, 7:50 pm
by Armelin
Thanks for reporting this bug and a solution will be uploaded on our Bitbucket downloads page.

Here is an example anyway

Code: Select all

function keyHook(playerId, virtualKey, isKeyUp)
	local i = 0
	if isKeyUp then i = 1 end
	sendPlayerMsg(playerId, "Key " .. virtualKey .. " status: " .. i, 0xFFFF0000)
end
registerEvent("keyHook", "onPlayerKeyPress")


function playerSpawnCredentials(playerid)
	--Whatever code you wanna have here
	
	setPlayerKeyHook(playerid, 0x41, true) -- 0x41 is the A key
end
registerEvent("playerSpawnCredentials", "onPlayerCredential")

Re: onPlayerKeyPress problem

Posted: September 7th, 2018, 10:55 pm
by wbty
Thanks, it works. That was very quick fix you guys are awesome.