Jump to content

Keys


Rick
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

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

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

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...