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 


[SCRIPT] Hotkeys (Actually hotkeys*).

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Thu Mar 13, 2014 2:46 pm    Post subject: [SCRIPT] Hotkeys (Actually hotkeys*). Reply with quote

Well,
I'm pretty sure that many of the people who used the C.E hotkey (when it comes to scripting) ain't so great, because it repeats the function when user holds the key...

So I wrote a simple script that should allow you to have an actual hotkey.
This script only allows to insert 1 key*, if anyone needs more, you may feel free to make it Very Happy.

Script :
Code:
local hotkeys = {Keys = {}; Status = {};};
hotkeys.AddHotKey =    function (hotkey,func)
                        if (not hotkeys.Keys[hotkey]) then
                           hotkeys.Keys[hotkey] = {};
                        end
                        hotkeys.Keys[hotkey][#hotkeys.Keys[hotkey]+1] = {};
                        local Table = hotkeys.Keys[hotkey][#hotkeys.Keys[hotkey]]
                        Table.func = func
                        Table.enabled = true
                        Table.destroy = function () Table.enabled = nil; Table.func = nil; Table.destroy = nil; end;
                        return Table
                     end
createNativeThread( -- This might not be the best idea, but I do enjoy having an instant response, so this method works pretty great.
function (self)
   while 1==1 do
      for hotkey,tablehotkey in pairs(hotkeys.Keys) do
         if ((not hotkeys.Status[hotkey]) and isKeyPressed(hotkey)) then
            hotkeys.Status[hotkey] = true;
            for k,tab in pairs(tablehotkey) do
               if (tab.enabled and tab.func) then
                  tab.func();
               end
            end
         elseif (not(isKeyPressed(hotkey))) then
            hotkeys.Status[hotkey] = false;
         end
      end
   end
end)
createHotkey = hotkeys.AddHotKey -- (First parameter is key, second parameter is function)


Usage (Example):
Code:
Hotkey1 = createHotkey(VK_UP, function () print(2) end); -- When pressing VK_UP it'll call the function which will print 2.
Hotkey1.enabled = true; -- Prevents from executing the function but does destroy the hotkey.
Hotkey1.destroy(); -- Destroys hotkey (Sort of, to be accurate it just removes the key, the function and the destroy function.. basically nilling it, but Hotkey1 will remain as a 'table'



Dark byte, it'll be awesome if you'll add it to the next C.E version (With multiply hotkeys options of course Very Happy).

Anyway guys, happy cheating!

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Thu Mar 13, 2014 7:33 pm    Post subject: Reply with quote

By default CE has "Delay between reactivating hotkeys" set to 100 milliseconds. I usually change that value to 200 or 300. You can change that in CE Settings: "Cheat Engine settings -> Hotkeys"


Or, you can use Lua function: setGlobalDelayBetweenHotkeyActivation
e.g.
Code:
setGlobalDelayBetweenHotkeyActivation(200)

This override delay value we see in CE settings. This setting is not saved in the registry.
You can use it for trainers.



You can also change delay for every created hotkey individually. There is DelayBetweenActivate property.
e.g.
Code:
hk1 = createHotkey(enableCheat0, VK_F1)
hk1.DelayBetweenActivate = 400


That way we can prevent disabling cheat accidentally (when we wanted to just enable it).


Edit:
typo

_________________


Last edited by mgr.inz.Player on Sun Jun 26, 2016 2:11 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Jun 26, 2016 2:11 pm    Post subject: "non repeating" hotkeys Reply with quote

"non repeating" hotkeys:
Code:
function createNonRepHotkey(func, ...)
  local getTickCount=getTickCount
  local lastTickCount=0
  local function changedBehaviour (sender)
    local TC = getTickCount()
    --call orig func when elap is bigger than 200ms
    if (TC - lastTickCount)>200 then func(sender) end
    lastTickCount = TC
  end

  local hk = createHotkey(changedBehaviour, ...)
  hk.DelayBetweenActivate = 10
  return hk
end



Usage is the same as normal hotkey:
Code:
function hotkey1func()
  print('hotkey1')
end

hotkey1 = createNonRepHotkey(hotkey1func, VK_F2, VK_LCONTROL)

_________________
Back to top
View user's profile Send private message MSN Messenger
Dsilencio
How do I cheat?
Reputation: 0

Joined: 26 Sep 2019
Posts: 6

PostPosted: Sat Sep 28, 2019 8:06 am    Post subject: Programing Reply with quote

I have a code AutoHotKey and I want to make it auto-assemble in Cheat Engine, how would it auto-assemble this code?

x::
loop {
send {1 DOWN}
sleep, 100
send {1 UP}
}
Return

I'm not interested in activating the script by pressing "X" I can enable and disable it by [ENABLE] //activated
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Wed Oct 09, 2019 2:14 am    Post subject: Reply with quote

Check this logic
https://forum.cheatengine.org/viewtopic.php?t=609811

(sorry for bump)

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
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 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