How to make a hotkey from a lua script?

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
User avatar
megupets
Cheater
Cheater
Posts: 25
Joined: Fri Jun 17, 2022 1:20 am
Reputation: 12

How to make a hotkey from a lua script?

Post by megupets »

Trying to build a trainer and have it run a Lua script by pressing a hotkey.
Is there a way to achieve this?
Most tutorials on YT talk about making trainers from scratch with Lua but could not find anything about this specific task I need for CE.
Any help or pointers will be mostly appreciated!

SarashJessicaParker
Expert Cheater
Expert Cheater
Posts: 59
Joined: Sat Sep 21, 2019 4:21 pm
Reputation: 41

Re: How to make a hotkey from a lua script?

Post by SarashJessicaParker »

ooopps read that wrong

User avatar
LeFiXER
LeFixer
LeFixer
Posts: 479
Joined: Wed Mar 24, 2021 9:35 am
Reputation: 242

Re: How to make a hotkey from a lua script?

Post by LeFiXER »

In the click event of the button on your trainer use if logic to determine which key is pressed:

Code: Select all

if keyCheck then keyCheck.destroy(); keyCheck = nil end

function executeScript(name)
	if name == nil then return nil end
	local mr = AddressList.getMemoryRecordByDescription(name)
	if mr ~= nil then
		mr.Active = true
	end
end

local keyCheck = createTimer(getMainForm())
keyCheck.Interval = 100
keyCheck.OnTimer = function()
		      if isKeyPressed(VK_KEY) then
		         executeScript('my_script_name') -- i.e. the description used on the entry of the script
		      end
		   end

User avatar
megupets
Cheater
Cheater
Posts: 25
Joined: Fri Jun 17, 2022 1:20 am
Reputation: 12

Re: How to make a hotkey from a lua script?

Post by megupets »

Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users