View previous topic :: View next topic |
Author |
Message |
jamils1992 Newbie cheater Reputation: 0
Joined: 21 Aug 2015 Posts: 10
|
Posted: Sun Sep 27, 2015 1:31 am Post subject: How to remove a hotkey in lua? |
|
|
i know i can use createHotkey(function, keys, ... ) to make hotkeys for a function ,How do i remove the created hotkey or replace it after it was created? .
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
|
Posted: Sun Sep 27, 2015 3:53 am Post subject: |
|
|
save the result of createHotkey (e.g. hk1) and when you wish to get rid of it call the destroy method (hk1.destroy() )
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
lolAnonymous Expert Cheater Reputation: 1
Joined: 19 Jul 2015 Posts: 154
|
Posted: Sun Sep 27, 2015 5:04 am Post subject: |
|
|
Darkbyte need a little help of u , we use form.hide(name) to hide the form or form.show... To show the form but now I want to show/hide a Cetrainer extension... I don't have its cheat table/script and I don't want to put my name on the CEtrainer... So is there any method to show and hide a CETrainer... ?
Thanks In Advance
|
|
Back to top |
|
|
MarkiThePews How do I cheat? Reputation: 0
Joined: 14 Nov 2016 Posts: 4
|
Posted: Thu Nov 17, 2016 11:12 am Post subject: |
|
|
Dark Byte wrote: | save the result of createHotkey (e.g. hk1) and when you wish to get rid of it call the destroy method (hk1.destroy() ) |
How exactly ?
I'm having this AA:
Code: | {$lua}
[ENABLE]
createHotkey(CEButton1Click, VK_6)
createHotkey(CEButton3Click, VK_7)
createHotkey(CEButton4Click, VK_8)
createHotkey(CEButton5Click, VK_9)
createHotkey(CEButton2Click, VK_0)
[DISABLE] |
so how can i disable those hotkey in ENABLE with the DISABLE section code ?
EDIT:
Oh nvm, i've figure it out:
Code: | {$lua}
[ENABLE]
midk = createHotkey(CEButton1Click, VK_6)
highk = createHotkey(CEButton3Click, VK_7)
shighk = createHotkey(CEButton4Click, VK_8)
flyk = createHotkey(CEButton5Click, VK_9)
normalk = createHotkey(CEButton2Click, VK_0)
[DISABLE]
midk.destroy()
highk.destroy()
shighk.destroy()
flyk.destroy()
normalk.destroy() |
_________________
Bad grammar, sorry |
|
Back to top |
|
|
ner0 Cheater Reputation: 0
Joined: 10 Dec 2011 Posts: 32
|
Posted: Tue Jan 24, 2017 12:58 pm Post subject: |
|
|
I'm having an issue where destroying an hotkey freezes the trainer.
For example:
Code: | function runMe()
if myHotkey then
myHotkey.destroy()
myHotkey = nil
end
-- DO MEMORY SCAN HERE--
myHotkey = createHotkey(runMe, VK_END)
end
myHotkey = createHotkey(runMe, VK_END) |
What I'm trying to do is disable the hotkey during the scan and then restore the hotkey once the scan completes. The issue is that it freezes the trainer as soon as I use the destroy method on the hotkey.
Any ideas?
Thank you!
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Tue Jan 24, 2017 2:48 pm Post subject: |
|
|
Do not create nor destroy hotkey object inside OnHotkey function of other hotkey.
Also, if you have memory record with set hotkey, and this memory record is AA script with embedded Lua script, CE will crash if you create or destroy Hotkey object.
_________________
|
|
Back to top |
|
|
ner0 Cheater Reputation: 0
Joined: 10 Dec 2011 Posts: 32
|
Posted: Tue Jan 24, 2017 4:05 pm Post subject: |
|
|
mgr.inz.Player wrote: | Do not create nor destroy hotkey object inside OnHotkey function of other hotkey.
Also, if you have memory record with set hotkey, and this memory record is AA script with embedded Lua script, CE will crash if you create or destroy Hotkey object. |
I don't understand completely what you mean.
Part of what I understand is that I can't destroy an hotkey from inside the function that called it. But then, if I try to have a second function destroying the hotkey then it results in the same problem. Also not sure what you mean by 'OnHotkey functions'.
Why doesn't this work then:
Code: | function useMe()
runMe()
end
function runMe()
if myHotkey then
myHotkey.destroy()
myHotkey = nil
end
-- DO MEMORY SCAN HERE--
end
myHotkey = createHotkey(useMe, VK_END) |
A working suggestion would be much appreciated. Thanks!
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Tue Jan 24, 2017 4:30 pm Post subject: |
|
|
Quote: | if I try to have a second function destroying the hotkey then it results in the same problem. |
You didn't change a thing.
When you press a hotkey it is like this: execute useMe, call runMe, destroy hotkey, exit from runMe, return to useMe, exit from useMe.
But, you don't have to destroy and recreate hotkey object:
Code: | skipRunMe = false
function runMe()
if skipRunMe then return end
skipRunMe = true
-- DO MEMORY SCAN HERE--
skipRunMe = false
end
myHotkey = createHotkey(runMe, VK_END) |
_________________
Last edited by mgr.inz.Player on Tue Jan 24, 2017 4:35 pm; edited 1 time in total |
|
Back to top |
|
|
ner0 Cheater Reputation: 0
Joined: 10 Dec 2011 Posts: 32
|
Posted: Tue Jan 24, 2017 4:35 pm Post subject: |
|
|
mgr.inz.Player wrote: | Quote: | if I try to have a second function destroying the hotkey then it results in the same problem. |
You didn't change a thing.
When you press a hotkey it is like this: execute useMe, call runMe, exit from runMe, return to useMe, exit from useMe. |
Right...
As you have noticed I don't follow how Cheat Engine handles hotkeys.
I did change the part where I use a second function and removed the reassignment of the hotkey inside the function. But essentially I'm just randomly putting code together in hoping that I accidentally make it work. That Ouroboros analogy wasn't helpful in the least... any practical suggestion, please?
EDIT:
mgr.inz.Player wrote: | Code: | skipRunMe = false
function runMe()
if skipRunMe then return end
skipRunMe = true
-- DO MEMORY SCAN HERE--
skipRunMe = false
end
myHotkey = createHotkey(runMe, VK_END) |
|
Absolutely!
I was so determined to use the 'destroy' function that something this simple never crossed my mind. Thanks a lot!
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4289
|
Posted: Tue Jan 24, 2017 5:01 pm Post subject: |
|
|
Any keypresses made while the OnHotkey function is being executed shouldn't invoke the OnHotkey function further. What exactly are you doing in the OnHotkey function that this would be a problem?
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
ner0 Cheater Reputation: 0
Joined: 10 Dec 2011 Posts: 32
|
Posted: Tue Jan 24, 2017 5:06 pm Post subject: |
|
|
ParkourPenguin wrote: | Any keypresses made while the OnHotkey function is being executed shouldn't invoke the OnHotkey function further. What exactly are you doing in the OnHotkey function that this would be a problem? |
Well, that is a good question.
I was under the impression that if I called a function through the hotkey that it would execute the function multiple times concurrently or in sequence of one another. To avoid this with buttons I simply disabled them until the function ends, in part it also indicates that the process is ongoing.
In this particular case, the function called by the hotkey performs a memory scan. If what you say is true then would it be correct to assume that the same function will never run two or more scans simultaneously, or sequentially, and that there is no need at all to destroy or use switches to verify if the process initiated by the hotkey is pending?
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Tue Jan 24, 2017 5:10 pm Post subject: |
|
|
Depends on what actually is under "-- DO MEMORY SCAN HERE--"
Do you use processMessages() ?
_________________
|
|
Back to top |
|
|
ner0 Cheater Reputation: 0
Joined: 10 Dec 2011 Posts: 32
|
Posted: Tue Jan 24, 2017 5:15 pm Post subject: |
|
|
mgr.inz.Player wrote: | Depends on what actually is under "-- DO MEMORY SCAN HERE--"
Do you use processMessages() ? |
I don't.
Basically this is the code that is present where -- DO MEMORY SCAN HERE-- (actually this is the whole function)
Code: | function findAndReplace(findValue, replaceWith)
memscan = createMemScan()
foundlist = createFoundList(memscan)
protectionflags = "+W*X*C"
memscan.firstScan(soExactValue, vtInteger, rtTruncated, findValue, nil,
"00000000", "7FFFFFFF", protectionflags, fsmAligned, "4",
false, false, false, false)
memscan.waitTillDone()
foundlist.initialize()
for i=0, foundlist.Count-1 do
writeInteger(foundlist.Address[i], replaceWith)
end
sleep(50)
foundlist.destroy()
sleep(50)
memscan.destroy()
end |
So, no need for switches or anything in your opinion?
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Tue Jan 24, 2017 5:55 pm Post subject: |
|
|
I think you can keep the switch. It won't break anything.
_________________
|
|
Back to top |
|
|
ner0 Cheater Reputation: 0
Joined: 10 Dec 2011 Posts: 32
|
Posted: Tue Jan 24, 2017 6:06 pm Post subject: |
|
|
mgr.inz.Player wrote: | I think you can keep the switch. It won't break anything. |
Ok, yeah it shouldn't be a problem.
Although this doesn't seem to be as consistent as expected... if I spam the hot key several times and stop, then the next time I press the hotkey it'll execute the function 3 times in a row. I have the hotkey delay set at 500ms and yet this will happen nonetheless. Not if I don't spam the hotkey though, weird...
EDIT: Nevermind, it's cheat engine that behaves weirdly after a few... closing CE and reopening goes away with the weirdness.
|
|
Back to top |
|
|
|