gregdwilson Posted June 5, 2015 Share Posted June 5, 2015 (edited) 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 June 5, 2015 by gregdwilson Link to comment https://forums.kleientertainment.com/forums/topic/54853-keydownhandler-help/ Share on other sites More sharing options...
gregdwilson Posted June 6, 2015 Author Share Posted June 6, 2015 Figured it out. I tied into the click event and manually removed the old handlers. I can post the code if anyone is interested. Link to comment https://forums.kleientertainment.com/forums/topic/54853-keydownhandler-help/#findComment-644249 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now