Jump to content

Recommended Posts

I have a button that is set to a given key but I would like to be able to reassign that key in game. Ultimately, I would like it only to set if it is the focus and the control button is down. Here is what I have so far which seems to work sporadically. I'm not sure why it works sometimes and sometimes it doesn't. Any help would be appreciated.

local TheInput = GLOBAL.TheInputlocal oldkey = GLOBAL.KEY_Z--This sets up the text that shows what key is currently assigned.self.DragonClaw.DragonClaw_key = self.DragonClaw:AddChild(Text(GLOBAL.TALKINGFONT, 30))	self.DragonClaw.DragonClaw_key:SetColour(154/255, 130/255, 104/255, 1)	self.DragonClaw.DragonClaw_key:SetPosition(20,20,0)--The initial setting of the hotkeyTheInput:AddKeyDownHandler(oldkey, function()				if not GLOBAL.IsPaused() then				SendModRPCToServer(MOD_RPC["Shadow Dragons"]["DCC"])				endend)--This removes the old hotkey assignment and assigns a new hotkeyfunction self.DragonClaw:OnRawKey(key,down)			if self.focus then			TheInput.onkeydown:RemoveHandler(TheInput.onkeydown:GetHandlersForEvent(oldkey))				TheInput:AddKeyDownHandler(key, function()				if not GLOBAL.IsPaused() then				SendModRPCToServer(MOD_RPC["Shadow Dragons"]["DCC"])				end			end)					self.DragonClaw_key:SetString(GLOBAL.STRINGS.UI.CONTROLSSCREEN.INPUTS[1][key])			oldkey = key						endend
Edited by gregdwilson
Link to comment
https://forums.kleientertainment.com/forums/topic/54853-keydownhandler-help/
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...