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 


Checking for key presses

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
LostInTransliteration
How do I cheat?
Reputation: 0

Joined: 25 Aug 2021
Posts: 9

PostPosted: Sat Jan 15, 2022 9:32 am    Post subject: Checking for key presses Reply with quote

I'm working on a script that overwrites normal camera controls. Currently to check for key presses while the script is active, I have a timer running that checks for key presses like this:

Code:

tflycam = createTimer(nil, false)
tflycam.Interval = 100
tflycam.Enabled = false
tflycam.OnTimer = function(flycamfunct)
-----------------------------------------
  if (isKeyPressed(VK_W)) then
    writeFloat(cameraX,readFloat(cameraX)+1) --//actual calculations abridged in this post for readability
    end

  if (isKeyPressed(VK_S)) then
    writeFloat(cameraX,readFloat(cameraX)-1) --//actual calculations abridged in this post for readability
    end

  --//and so on for all other hotkeys in use in this flycam
-----------------------------------------
  end


But there's gotta be a smarter way to do this that isn't just a dozen "if ... then" checks every 100 ticks. What's a better way to do this?
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Sat Jan 15, 2022 10:22 am    Post subject: Reply with quote

i guess its not(since script will write camera x always when key is pressed)
not topic related:
From your syntax i see that you are c++,c# coder

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sat Jan 15, 2022 10:24 am    Post subject: Reply with quote

Never really messed with it, but from the "celua.txt" file.
Code:

GenericHotkey Class : (Inheritance:  Object)
createHotkey(function, keys, ...) : returns an initialized GenericHotkey class object. Maximum of 5 keys
createHotkey(function, {keys, ...}) : ^

properties
  DelayBetweenActivate: integer - Interval in milliseconds that determines the minimum time between hotkey activations. If 0, the global delay is used
  onHotkey: The function to call when the hotkey is pressed

methods
  getKeys()
  setKeys(key, ....)
  setOnHotkey(table)
  getOnHotkey


But yeah the options for what you want kind of thing seem limited; it's either hotkey, timer, or thread.

_________________
Back to top
View user's profile Send private message Visit poster's website
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