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 


How do I add a while holding key to activate this script?

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

Joined: 15 Jan 2023
Posts: 1

PostPosted: Sun Jan 15, 2023 11:49 pm    Post subject: How do I add a while holding key to activate this script? Reply with quote

{$Lua}
if syntaxcheck then return end

[ENABLE]
superLuaAutoClickForTriggerbot_thread = createNativeThread(function (thread)
thread.freeOnTerminate(false)
thread.Name = 'superLuaAutoClickForTriggerbot_thread'
local crshair
while not thread.Terminated do
local crshair = readInteger('2130B3B4888')
if crshair == 1 then
mouse_event(MOUSEEVENTF_LEFTDOWN)
sleep(10)
mouse_event(MOUSEEVENTF_LEFTUP)
end
sleep(10)
end
end)

[DISABLE]
if superLuaAutoClickForTriggerbot_thread then -- kill thread
superLuaAutoClickForTriggerbot_thread.terminate()
superLuaAutoClickForTriggerbot_thread.waitfor()
superLuaAutoClickForTriggerbot_thread.destroy()
superLuaAutoClickForTriggerbot_thread=nil
end
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Mon Jan 16, 2023 1:37 am    Post subject: Reply with quote

You only want that code running while a key is being held down?

Set a hotkey to enable the script (not toggle, only enable). In the thread, check to see if the key is still being pressed. If not, disable the script. There's a `memrec` variable defined by CE similar to the `syntaxcheck` variable. You probably need to disable it from the main thread, so use synchronize(...)

It might be simpler to forego an AA script entirely. Create the thread once in the main Lua script. If the particular key is being held down, run the existing code for the thread; if it's not held down, sleep a little longer (hotkey poll interval).

_________________
I don't know where I'm going, but I'll figure it out when I get there.
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: Mon Jan 16, 2023 2:24 am    Post subject: Reply with quote

maybe better use timer than while in thread, while true may cause bigger CPU usage, or just set sleep function to 20 or 50, so it won't take any performance
_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Chuck1982
How do I cheat?
Reputation: 0

Joined: 23 Jan 2023
Posts: 8

PostPosted: Fri Jan 27, 2023 8:51 am    Post subject: Reply with quote

Frouk wrote:
maybe better use timer than while in thread, while true may cause bigger CPU usage, or just set sleep function to 20 or 50, so it won't take any performance


Use the while loop for the key event being down, but inside that loop set a sleep so the CPU doesn't get hammered, maybe?
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Fri Jan 27, 2023 10:43 am    Post subject: Reply with quote

CE now supports 'while pressed' functionality for hotkeys.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Discussions 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