Rick Posted December 29, 2009 Share Posted December 29, 2009 Is there an easy way to get a text value of a key related to the number value of a key or do I need to brute force it manually like: keys["KEY_W"] = KEY_W keys["KEY_Q"] = KEY_Q ... I'm making a configurable object where the drop down of the setting will list every key in it. I then take the text value they selected and convert it to something that can be used in KeyDown()/KeyHit(). I can do this manually, but wasn't sure if there was some looping trick I might be able to do to make the code shorter. Quote Link to comment Share on other sites More sharing options...
macklebee Posted December 29, 2009 Share Posted December 29, 2009 require("scripts/class") local class=CreateClass(...) function class:InitDialog(grid) self.super:InitDialog(grid) group=grid:AddGroup("Keys") local letters = "KEY_"..string.char(65) for i = 66,90 do letters = letters..",".."KEY_"..string.char(i) end group:AddProperty("KEYS",PROPERTY_CHOICE,letters) group:Expand(1) end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Rick Posted December 29, 2009 Author Share Posted December 29, 2009 That works for the letters, so I suppose I'll have to manually do all the other keys though? Arrows, Home, Insert, etc Quote Link to comment Share on other sites More sharing options...
macklebee Posted December 29, 2009 Share Posted December 29, 2009 just use all of the equivalent ASCII characters/numbers you wish to use... if there is a break in the numbering then yes you have to take that into account in the for loop... as for the keys that you want like Backspace, Home, etc... just add them all with just one line local class=CreateClass(...) function class:InitDialog(grid) self.super:InitDialog(grid) group=grid:AddGroup("Keys") local letters = "KEY_UP,KEY_DOWN,KEY_RIGHT,KEY_LEFT,KEY_BACKSPACE" for i = 65,90 do letters = letters..",".."KEY_"..string.char(i) end group:AddProperty("KEYS",PROPERTY_CHOICE,letters) group:Expand(1) end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.