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 can i loop mouse clicks by holding it?

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

Joined: 16 Jun 2018
Posts: 3

PostPosted: Sat Jun 16, 2018 7:37 am    Post subject: how can i loop mouse clicks by holding it? Reply with quote

hi everyone, i'm newbie here.

i want to know how can i loop mouse clicks by holding it?

in this code i want to change the hot key from X to holding R mouse button.
so when i hold down R mouse button, it will auto R clicks with interval 90

Code:

function CECheckbox2Click(sender)

  if sender.state==1 then

if myhotkey1 then
  myhotkey1.Destroy()
  myhotkey1 = nil
end

function killmytimer()
  if mytimer then
    mytimer.Destroy()
    mytimer = nil
  end
end

myhotkey1 = createHotkey(function()
  if mytimer then
    killmytimer()
  else
    mytimer=createTimer()
    mytimer.interval=90
    mytimer.OnTimer=function()
      mouse_event(MOUSEEVENTF_RIGHTDOWN)
      mouse_event(MOUSEEVENTF_RIGHTUP)
     
    end
  end

end, VK_X)

else
myhotkey1.Destroy()
  myhotkey1 = nil
  end


end

Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sat Jun 16, 2018 10:46 am    Post subject: Reply with quote

For some reason I expect the code constantly changing the state of the mouse button being up and down is going to interfere with the code that checks whether the mouse is down for the hotkey...

I tried a couple basic things in lua but didn't have any luck so, good luck Smile

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
LewcowVaal
Advanced Cheater
Reputation: 0

Joined: 30 Dec 2017
Posts: 63

PostPosted: Sat Jun 16, 2018 10:54 am    Post subject: Reply with quote

FreeER wrote:
For some reason I expect the code constantly changing the state of the mouse button being up and down is going to interfere with the code that checks whether the mouse is down for the hotkey...

I tried a couple basic things in lua but didn't have any luck so, good luck Smile


Actually i was interested in doing this too. I tried some things but no luck, hopefully some crazy mind here comes up with a solution Smile even because i'm not a LUA expert.
Back to top
View user's profile Send private message
yousefh
How do I cheat?
Reputation: 0

Joined: 16 Jun 2018
Posts: 3

PostPosted: Sat Jun 16, 2018 1:15 pm    Post subject: Reply with quote

LewcowVaal wrote:
FreeER wrote:
For some reason I expect the code constantly changing the state of the mouse button being up and down is going to interfere with the code that checks whether the mouse is down for the hotkey...

I tried a couple basic things in lua but didn't have any luck so, good luck Smile


Actually i was interested in doing this too. I tried some things but no luck, hopefully some crazy mind here comes up with a solution Smile even because i'm not a LUA expert.


yes that's why i'm asking, changing state to button up while i'm holding the right mouse... i hope i find a solution for that
Back to top
View user's profile Send private message
LewcowVaal
Advanced Cheater
Reputation: 0

Joined: 30 Dec 2017
Posts: 63

PostPosted: Mon Jun 18, 2018 8:43 am    Post subject: Reply with quote

I summon the mighty Darkbyte
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Mon Jun 18, 2018 10:54 am    Post subject: Reply with quote

Use a different key. It's not that much of an inconvenience. If anything, it lets the user still use the right mouse button if/when they don't need it to repeat.

Disregarding that, the input sent to the game shouldn't interfere with the hotkey trigger. You need to be more specific than mouse_event. For example, send a message directly to the window:
Code:
if hk then hk.destroy() end
if frm then frm.destroy() end

frm = createForm()

local btn = createButton(frm)
btn.Width = 120
btn.AnchorSideLeft.Control = frm
btn.AnchorSideLeft.Side = asrCenter
btn.AnchorSideTop.Control = frm
btn.AnchorSideTop.Side = asrCenter
btn.Caption = 'clicked 0 times'

local i = 0
btn.OnClick = function(b) i = i + 1; b.Caption = ('clicked %d times'):format(i) end

hk = createHotkey(function()
  if frm and frm.isForegroundWindow() then
    sendMessage(btn.handle, 0x0201, 1, 0)
    sendMessage(btn.handle, 0x0202, 0, 0)
  end
end, VK_LBUTTON)
hk.delayBetweenActivate = 90

Code injection is always an option.

_________________
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
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Mon Jun 18, 2018 11:18 am    Post subject: Reply with quote

rebind the action associated with the left mouse button in the game to some other button, and then use a left mouse as a hotkey which initiates a timer that repeatedly presses that button up and down and check if the mouse button is still down. And if not, stop the timer

or use a different button, e.g mouse button 4 or 5, or the scroll down

_________________
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
kantoboy69
Advanced Cheater
Reputation: 2

Joined: 31 Mar 2010
Posts: 71
Location: Manila

PostPosted: Tue Jun 19, 2018 4:26 am    Post subject: Reply with quote

I'm not sure if lua can call windows api but you can try

USER32.GetAsyncKeyState

And put it on a timer to check if the right mouse button is down

_________________
Cheater always prosper Hitler
Back to top
View user's profile Send private message
yousefh
How do I cheat?
Reputation: 0

Joined: 16 Jun 2018
Posts: 3

PostPosted: Wed Jun 20, 2018 9:50 am    Post subject: Reply with quote

ParkourPenguin wrote:
Use a different key. It's not that much of an inconvenience. If anything, it lets the user still use the right mouse button if/when they don't need it to repeat.

Disregarding that, the input sent to the game shouldn't interfere with the hotkey trigger. You need to be more specific than mouse_event. For example, send a message directly to the window:
Code:
if hk then hk.destroy() end
if frm then frm.destroy() end

frm = createForm()

local btn = createButton(frm)
btn.Width = 120
btn.AnchorSideLeft.Control = frm
btn.AnchorSideLeft.Side = asrCenter
btn.AnchorSideTop.Control = frm
btn.AnchorSideTop.Side = asrCenter
btn.Caption = 'clicked 0 times'

local i = 0
btn.OnClick = function(b) i = i + 1; b.Caption = ('clicked %d times'):format(i) end

hk = createHotkey(function()
  if frm and frm.isForegroundWindow() then
    sendMessage(btn.handle, 0x0201, 1, 0)
    sendMessage(btn.handle, 0x0202, 0, 0)
  end
end, VK_LBUTTON)
hk.delayBetweenActivate = 90

Code injection is always an option.


this is a great solution, and i did try it before.
but the problem i'm always facing is how to get the window handle?
the game i'm talking about here is multi windows, and idk which window i should i send the message to

** there should be a image here for the windows but i'm not allowed to post urls yet. Very Happy


Dark Byte wrote:
rebind the action associated with the left mouse button in the game to some other button, and then use a left mouse as a hotkey which initiates a timer that repeatedly presses that button up and down and check if the mouse button is still down. And if not, stop the timer

or use a different button, e.g mouse button 4 or 5, or the scroll down


changing controls is not allowed in this game


Last edited by yousefh on Wed Jun 20, 2018 6:06 pm; edited 1 time in total
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Wed Jun 20, 2018 11:15 am    Post subject: Reply with quote

You should remove that image (see FAQ).

Find a window via findWindow and get to nearby windows via getWindow (CE exposes both to Lua). Identify it via class, name, parent, children, depth, etc.

I don't know which one is correct. Worst case, use trial and error to figure it out. Maybe sending messages to all of them will work, or only some of them.


If you really want to be exact about this, hook the thread's message loop. Watch for relevant messages, add/remove destination window handles to/from a list, and process that list periodically from CE. You'll need to be careful if you want to do this correctly (e.g. send btn_up message before next btn_down message, maybe drop some messages, avoid race conditions and data races, etc.).

_________________
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
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