Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Problem setting IsKeyPressed with a variable

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
AmyGrrl
Cheater
Reputation: 0

Joined: 15 Dec 2016
Posts: 31

PostPosted: Fri Nov 02, 2018 4:51 pm    Post subject: Problem setting IsKeyPressed with a variable Reply with quote

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
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Fri Nov 02, 2018 8:38 pm    Post subject: Reply with quote

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
Code:
ActivateKey = ("F"):byte(1)
or
Code:
ActivateKey = string.byte('F',1)

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites