Posted: Fri Nov 02, 2018 4:51 pm Post subject: Problem setting IsKeyPressed with a variable
I'm trying to make a HotKey that can be changed at anytime. You can set the key you want to use to activate in a variable. However it doesn't seem like IsKeyPressed likes using variables. Have tried everything I can think of. Below is just a small test example of one of the ways I have tried to get this to work.
This works when hardcoded
Code:
function ActivateLoop(thread)
while true do
if (isKeyPressed(VK_F)) then
print ("It Does What I Put Here")
else
end
Sleep(100)
end
end
This is just one example of something I tried. This always fails. Will give an error or just do nothing when the key is pressed. Have tried at least 20 different ways to do VK_ with a variable. I'm thinking .. is not what I should be using for this.
Code:
ActivateKey="F"
function ActivateLoop(thread)
while true do
if (isKeyPressed(VK_ .. ActivateKey)) then
print ("It Does What I Put Here")
else
end
Sleep(100)
end
end
VK_F is a variable. VK_ is a valid variable name so what you're doing is trying to concatenate the variable VK_ which is almost certainly nil with the variable ActivateKey. Use _G["VK_" .. ActivateKey] (_G is the global environment table), or... you know, just set ActivateKey to the value of the variable VK_F with
Code:
ActivateKey = VK_F
alternatively the code for letters is just the ascii value of the uppercase letter so you could use
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum