Page 1 of 1

How to make a hotkey from a lua script?

Posted: Sun Jun 26, 2022 5:42 am
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!

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

Posted: Sun Jun 26, 2022 5:43 pm
by SarashJessicaParker
ooopps read that wrong

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

Posted: Mon Jun 27, 2022 1:20 pm
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

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

Posted: Fri Jul 01, 2022 6:30 pm
by megupets
Thanks!