TEPA6ANT Posted May 31, 2019 Share Posted May 31, 2019 KeyDown and KeyHit is good. But they return boolean variable. Is it possible to find out the current button pressed? Quote Link to comment Share on other sites More sharing options...
gamecreator Posted May 31, 2019 Share Posted May 31, 2019 This used to not be possible without coding it yourself but I wonder how Leadwerks handles GUI edit boxes. Maybe there's Lua code you can look at. 1 Quote Link to comment Share on other sites More sharing options...
TEPA6ANT Posted May 31, 2019 Author Share Posted May 31, 2019 I think I earned the title of "bad programmer" ))) local index for index=1, 255 do if window:KeyHit(index) then System:Print(index) end end Quote Link to comment Share on other sites More sharing options...
GorzenDev Posted June 1, 2019 Share Posted June 1, 2019 i used to do something like this... this will only add keyinfo to the Keys table when a key is actually used. to make it work you would need to add a call to PreUpdate() in your main loop. to check a key's state you would call eg: IsKeyUp(Key.W) or IsKeyDown(Key.W). function SetKeyboardInfoPack() local pack = { Keys = {}, -- FlushKeyInfo = function (self, resetHit, key) if key ~= nil then local nHit = 0 if self.Keys[key] ~= nil and resetHit == false then nHit = self.Keys[key].hit end self.Keys[key] = {down = false, up = false, hit = nHit} else local nHit = 0 for key,value in pairs(self.Keys) do if resetHit == false then nHit = self.Keys[key].hit end self.Keys[key] = {down = false, up = false, hit = nHit} end end end, -- PreUpdate = function (self) self:RefreshKeyStates() end, -- IsKeyDown = function (self, key) --create a key record if not already exists and check the keystate if self.Keys[key] == nil then self.Keys[key] = {down = false, up = false, hit = 0} self:RefreshKey(key) end --return keystate return self.Keys[key].down end, -- IsKeyUp = function (self, key) --create a key record if not already exists and check the keystate if self.Keys[key] == nil then self.Keys[key] = {down = false, up = false, hit = 0} self:RefreshKey(key) end --return keystate return self.Keys[key].up end, Keyhits = function (self, key) --create a key record if not already exists and check the keystate if self.Keys[key] == nil then self.Keys[key] = {down = false, up = false, hit = 0} self:RefreshKey(key) end --return keystate return self.Keys[key].hit end, -- RefreshKeyStates = function (self) for key,value in pairs(self.Keys) do self:RefreshKey(key) end end, RefreshKey = function (self, key) if key ~= nil then if self.Keys[key] ~= nil then if window:KeyDown(key) then self.Keys[key].down = true self.Keys[key].up = false elseif self.Keys[key].down == true then --last state down self.Keys[key].down = false self.Keys[key].up = true self.Keys[key].hit = self.Keys[key].hit + 1 elseif self.Keys[key].up == true then --last state up self.Keys[key].down = false self.Keys[key].up = false end end end end } -- return pack end Quote 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.