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 


Hotkey 1 Action Only

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
kucingkembar
Advanced Cheater
Reputation: 0

Joined: 08 Oct 2020
Posts: 71

PostPosted: Fri Nov 27, 2020 1:21 am    Post subject: Hotkey 1 Action Only Reply with quote

sorry for the title, i dont know how to describe it,
i have this code:
Code:

TheValue = 1
createHotkey(
    function()
        TheValue = TheValue + 1
        print(TheValue)
    end,
    VK_NUMPAD0
)

I like when I press "Hotkey 0", TheValue will increase by 1, but the longer I press it TheValue keeps increasing, how to stopping this?,
thank you, have a nice day
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Fri Nov 27, 2020 1:59 am    Post subject: Reply with quote

Take a look here, https://forum.cheatengine.org/viewtopic.php?p=5679193#5679193
_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
kucingkembar
Advanced Cheater
Reputation: 0

Joined: 08 Oct 2020
Posts: 71

PostPosted: Fri Nov 27, 2020 2:46 am    Post subject: Reply with quote

thanks for the reply, I studied for 30 minutes and do not do any progress, sorry for my stupidity, can you write the working code as an example?
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Nov 27, 2020 3:43 am    Post subject: Reply with quote

kucingkembar wrote:
thanks for the reply, I studied for 30 minutes and do not do any progress, sorry for my stupidity, can you write the working code as an example?


Alternative, use key down event.

Code:
if f then f.destroy() end
f=createForm()
local TheValue = 1
function Form_KeyDown(sender,Key)
f.setFocus()
if Key==VK_NUMPAD0 then
TheValue=TheValue+1
print(TheValue)
end
end
f.OnKeyDown=Form_KeyDown

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Fri Nov 27, 2020 4:01 am    Post subject: Reply with quote

This is another example that is no different.

Code:
setGlobalDelayBetweenHotkeyActivation(400)

TheValue = 1
createHotkey(
    function()
        TheValue = TheValue + 1
        print(TheValue)
    end,
    VK_NUMPAD0
)
Back to top
View user's profile Send private message
kucingkembar
Advanced Cheater
Reputation: 0

Joined: 08 Oct 2020
Posts: 71

PostPosted: Fri Nov 27, 2020 4:47 am    Post subject: Reply with quote

sorry for the late reply, I just tried both codes

@DaSpamer
your code is good, but if I press faster than 400 ms, the hotkey will not be triggered, but it gives me some ideas of my other codes, thank you very much.

@Corroder your code is working as I intended, somehow I don't like when it pressed quite long it will repeat the "task", but this is the best (easiest) solution for me, thank you very much

Edit: I tried the code @Corroder, it not a hotkey, the form must activate while pressing the code
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Fri Nov 27, 2020 8:41 am    Post subject: Reply with quote

How fast are you pressing?
Code:
function createNonRepHotkey(func, ...)
  local getTickCount=getTickCount
  local lastTickCount=0
  local function changedBehaviour (sender)
    --call orig func when elap is bigger than 130ms
    if (getTickCount() - lastTickCount)>130 then func(sender) end
    lastTickCount = getTickCount()
  end

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

-- modify only this part;
function hotkey1func()
  print('hotkey1')
end
hotkey1 = createNonRepHotkey(hotkey1func, VK_F2)


If the above does not fit your needs, then this script (using threads) will for sure fit
https://forum.cheatengine.org/viewtopic.php?p=5524713#5524713

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
kucingkembar
Advanced Cheater
Reputation: 0

Joined: 08 Oct 2020
Posts: 71

PostPosted: Fri Nov 27, 2020 8:53 am    Post subject: Reply with quote

thank you @DaSpamer, your code is working,
answer about how fast I press the button?, now I create some kind of slide. from page 1 to 20, sometimes I like to go from 1 to 12 by repeatedly press the button 11 times, or similar to that
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