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 


How to remove a hotkey in lua?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
jamils1992
Newbie cheater
Reputation: 0

Joined: 21 Aug 2015
Posts: 10

PostPosted: Sun Sep 27, 2015 1:31 am    Post subject: How to remove a hotkey in lua? Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25287
Location: The netherlands

PostPosted: Sun Sep 27, 2015 3:53 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
lolAnonymous
Expert Cheater
Reputation: 1

Joined: 19 Jul 2015
Posts: 154

PostPosted: Sun Sep 27, 2015 5:04 am    Post subject: Reply with quote

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
View user's profile Send private message
MarkiThePews
How do I cheat?
Reputation: 0

Joined: 14 Nov 2016
Posts: 4

PostPosted: Thu Nov 17, 2016 11:12 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Tue Jan 24, 2017 12:58 pm    Post subject: Reply with quote

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
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: Tue Jan 24, 2017 2:48 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Tue Jan 24, 2017 4:05 pm    Post subject: Reply with quote

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
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: Tue Jan 24, 2017 4:30 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Tue Jan 24, 2017 4:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Tue Jan 24, 2017 5:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Tue Jan 24, 2017 5:06 pm    Post subject: Reply with quote

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
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: Tue Jan 24, 2017 5:10 pm    Post subject: Reply with quote

Depends on what actually is under "-- DO MEMORY SCAN HERE--"

Do you use processMessages() ?

_________________
Back to top
View user's profile Send private message MSN Messenger
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Tue Jan 24, 2017 5:15 pm    Post subject: Reply with quote

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
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: Tue Jan 24, 2017 5:55 pm    Post subject: Reply with quote

I think you can keep the switch. It won't break anything.
_________________
Back to top
View user's profile Send private message MSN Messenger
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Tue Jan 24, 2017 6:06 pm    Post subject: Reply with quote

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
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
Goto page 1, 2  Next
Page 1 of 2

 
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