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 


Cheat Engine hotkeys

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

Joined: 12 Jan 2018
Posts: 3

PostPosted: Fri Jan 12, 2018 12:14 pm    Post subject: Cheat Engine hotkeys Reply with quote

I want to know how can i make a implemented script active for as long as i hold a key, and after release it deactives. Thanks
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater
Reputation: 34

Joined: 09 Aug 2013
Posts: 893

PostPosted: Fri Jan 12, 2018 11:44 pm    Post subject: Reply with quote

There may be a simpler way but off the top of my head you can do something like this (basically, start a timer that checks to see if the first hotkey's first key is pressed and once it detects that it isn't it disables the script):

Code:
[ENABLE]
{$lua}
-- don't run when editing script
if syntaxcheck then return end
-- ignore hotkey stuff if not trigged by first hotkey
if not (memrec.HotkeyCount > 0 and memrec.Hotkey[0].Keys[1] and isKeyPressed(memrec.Hotkey[0].Keys[1])) then return end
local t = createTimer()
t.Interval = 100
t.OnTimer = function(t)
  -- sanity check to prevent errors
  if not (memrec.HotkeyCount > 0 and memrec.Hotkey[0].Keys[1]) then
    t.destroy()
    return
  end
  -- if key not pressed then disable script
  if not isKeyPressed(memrec.Hotkey[0].Keys[1]) then
    memrec.Active = false
    t.destroy()
  end
end
{$asm}

// ... whatever code

[DISABLE]


If you had multiple scripts you wanted to do this with then instead of copy/pasting that into each of them you could create a function in the table lua script (Table->Show Cheat Table Lua Script) eg.

Code:
function disableOnHotkeyRelease(memrec, hotkeyIndex)
  local function validHK(memrec,hotkeyIndex) return memrec.HotkeyCount > hotkeyIndex and memrec.Hotkey[hotkeyIndex].keys[1] end
  if not hotkeyIndex then hotkeyIndex = 0 end
  -- ignore hotkey stuff if not trigged by first hotkey
  if not (validHK(memrec,hotkeyIndex) and isKeyPressed(memrec.Hotkey[hotkeyIndex].Keys[1])) then return false end
  local t = createTimer()
  t.Interval = 100
  t.OnTimer = function(t)
    -- sanity check to prevent errors
    if not validHK(memrec,hotkeyIndex) then t.destroy(); return end
    -- if key not pressed then disable script
    if not isKeyPressed(memrec.Hotkey[hotkeyIndex].Keys[1]) then memrec.Active = false; t.destroy() end
  end
end


and then in each script you could use just
Code:
[ENABLE]
{$lua}
-- don't run when editing script
if syntaxcheck then return end
disableOnHotkeyRelease(memrec) -- optionally provide index to select different hotkey
{$asm}

[DISABLE]


note this is based on CE6.7, older versions would need to be modified (specifically, memrec didn't exist prior to CE 6.7 though there may be other differences)

tested with a hotkey set to 'enable' the script not toggle, note if you quickly tap the key then the script may 'lock' on and not disable after the key is released (presumably) due to the "ignore hotkey stuff if not trigged by first hotkey" check (which is there so you can manually enable the script and not have it immediately disable).
Back to top
View user's profile Send private message
Endarkened
How do I cheat?
Reputation: 0

Joined: 12 Jan 2018
Posts: 3

PostPosted: Sun Jan 14, 2018 4:11 pm    Post subject: Reply with quote

FreeER wrote:
There may be a simpler way but off the top of my head you can do something like this (basically, start a timer that checks to see if the first hotkey's first key is pressed and once it detects that it isn't it disables the script):

Code:
[ENABLE]
{$lua}
-- don't run when editing script
if syntaxcheck then return end
-- ignore hotkey stuff if not trigged by first hotkey
if not (memrec.HotkeyCount > 0 and memrec.Hotkey[0].Keys[1] and isKeyPressed(memrec.Hotkey[0].Keys[1])) then return end
local t = createTimer()
t.Interval = 100
t.OnTimer = function(t)
  -- sanity check to prevent errors
  if not (memrec.HotkeyCount > 0 and memrec.Hotkey[0].Keys[1]) then
    t.destroy()
    return
  end
  -- if key not pressed then disable script
  if not isKeyPressed(memrec.Hotkey[0].Keys[1]) then
    memrec.Active = false
    t.destroy()
  end
end
{$asm}

// ... whatever code

[DISABLE]


If you had multiple scripts you wanted to do this with then instead of copy/pasting that into each of them you could create a function in the table lua script (Table->Show Cheat Table Lua Script) eg.

Code:
function disableOnHotkeyRelease(memrec, hotkeyIndex)
  local function validHK(memrec,hotkeyIndex) return memrec.HotkeyCount > hotkeyIndex and memrec.Hotkey[hotkeyIndex].keys[1] end
  if not hotkeyIndex then hotkeyIndex = 0 end
  -- ignore hotkey stuff if not trigged by first hotkey
  if not (validHK(memrec,hotkeyIndex) and isKeyPressed(memrec.Hotkey[hotkeyIndex].Keys[1])) then return false end
  local t = createTimer()
  t.Interval = 100
  t.OnTimer = function(t)
    -- sanity check to prevent errors
    if not validHK(memrec,hotkeyIndex) then t.destroy(); return end
    -- if key not pressed then disable script
    if not isKeyPressed(memrec.Hotkey[hotkeyIndex].Keys[1]) then memrec.Active = false; t.destroy() end
  end
end


and then in each script you could use just
Code:
[ENABLE]
{$lua}
-- don't run when editing script
if syntaxcheck then return end
disableOnHotkeyRelease(memrec) -- optionally provide index to select different hotkey
{$asm}

[DISABLE]


note this is based on CE6.7, older versions would need to be modified (specifically, memrec didn't exist prior to CE 6.7 though there may be other differences)

tested with a hotkey set to 'enable' the script not toggle, note if you quickly tap the key then the script may 'lock' on and not disable after the key is released (presumably) due to the "ignore hotkey stuff if not trigged by first hotkey" check (which is there so you can manually enable the script and not have it immediately disable).

Sorry for the late response, i didnt get the mail. So i suck at this pretty much, i have never programmed sth like this before so if you could please tell me where do i put that first script or the last one, because it doesnt seem to work when i put it in the code of my script. Should i put it before or after dynamic allocations and definitions?
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater
Reputation: 34

Joined: 09 Aug 2013
Posts: 893

PostPosted: Sun Jan 14, 2018 4:21 pm    Post subject: Reply with quote

use
Code:
[ENABLE]
{$lua}
-- don't run when editing script
if syntaxcheck then return end
-- ignore hotkey stuff if not trigged by first hotkey
if not (memrec.HotkeyCount > 0 and memrec.Hotkey[0].Keys[1] and isKeyPressed(memrec.Hotkey[0].Keys[1])) then return end
local t = createTimer()
t.Interval = 100
t.OnTimer = function(t)
  -- sanity check to prevent errors
  if not (memrec.HotkeyCount > 0 and memrec.Hotkey[0].Keys[1]) then
    t.destroy()
    return
  end
  -- if key not pressed then disable script
  if not isKeyPressed(memrec.Hotkey[0].Keys[1]) then
    memrec.Active = false
    t.destroy()
  end
end
{$asm}

// ... whatever enable code

[DISABLE]

// ... whatever disable code


as your script and replace

"// ... whatever enable code" with whatever code you have for the enable section and "// ... whatever disable code " with whatever code you have for the disable section.
Back to top
View user's profile Send private message
Endarkened
How do I cheat?
Reputation: 0

Joined: 12 Jan 2018
Posts: 3

PostPosted: Mon Jan 15, 2018 4:26 pm    Post subject: Reply with quote

FreeER wrote:
use
Code:
[ENABLE]
{$lua}
-- don't run when editing script
if syntaxcheck then return end
-- ignore hotkey stuff if not trigged by first hotkey
if not (memrec.HotkeyCount > 0 and memrec.Hotkey[0].Keys[1] and isKeyPressed(memrec.Hotkey[0].Keys[1])) then return end
local t = createTimer()
t.Interval = 100
t.OnTimer = function(t)
  -- sanity check to prevent errors
  if not (memrec.HotkeyCount > 0 and memrec.Hotkey[0].Keys[1]) then
    t.destroy()
    return
  end
  -- if key not pressed then disable script
  if not isKeyPressed(memrec.Hotkey[0].Keys[1]) then
    memrec.Active = false
    t.destroy()
  end
end
{$asm}

// ... whatever enable code

[DISABLE]

// ... whatever disable code


as your script and replace

"// ... whatever enable code" with whatever code you have for the enable section and "// ... whatever disable code " with whatever code you have for the disable section.

Wow, now i tried it once again and it works flawlessly, but the 3 times i tried before it didnt. Thank you very much, appreciate it. All best!
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 Tutorials 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