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 


Mouse click with lua !! ?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Twistedfate
Expert Cheater
Reputation: 1

Joined: 11 Mar 2016
Posts: 231

PostPosted: Tue Aug 23, 2016 9:20 pm    Post subject: Mouse click with lua !! ? Reply with quote

Code:
hk = createHotkey(function() doKeyPress(VK_RBUTTON) end, VK_LBUTTON)



when i run this code nothing happens

but when i run this work

Code:
hk = createHotkey(function() doKeyPress(B) end, VK_LBUTTON)


I searched in main.lua didnot see anything about mouse clicks I thing
is there any function for this ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Aug 23, 2016 9:29 pm    Post subject: Reply with quote

in next version.
Now you have to use assembler code and call mouse_event with the proper commands

_________________
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
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Wed Aug 24, 2016 5:29 am    Post subject: This post has 1 review(s) Reply with quote

Something that allows me to stimulate mouse clicks,only in C.E 6.5.1, otherwise you need to workaround ExecuteCodeLocal.
This script is for 32 bit version only, convert it to 64bit if needed, you could place it in auto run and check if cheat engine is not 64bit, (I prefer 32bit for most cheats).

Code:
local ceasmcache,cegacache = {},{}
function autoAssembleEx(script,boolean,force)
   if (script and (not force) and ceasmcache[stringToMD5String(script)]) then
      return true
   end
   ceasmcache[stringToMD5String(script)] = true;
   return autoAssemble(script,boolean);
end
function getAddressEx(address,boolean)
   local s = cegacache[address];
   if (s) then
      return s
   end
   cegacache[address] = getAddress(address,boolean);
   return cegacache[address];
end
local sMainGSS = "globalalloc(CEGetScreenSize,$100)\nlabel(gw)\nlabel(gh)\nlabel(gcw)\nlabel(gch)\nCEGetScreenSize:\nxor eax,eax\nmov eax,[esp+4]\ncmp eax,0\nje gw\ncmp eax,1\nje gh\ncmp eax,2\nje gcw\ncmp eax,3\nje gch\npush eax\ncall GetSystemMetrics\nret 4\ngw:\npush 0\ncall GetSystemMetrics\nret 4\ngh:\npush 1\ncall GetSystemMetrics\nret 4\ngcw:\npush 10\ncall GetSystemMetrics\nret 4\ngch:\npush 11\ncall GetSystemMetrics\nret 4"
function getScreenSize(gCS)
   if (autoAssembleEx(sMainGSS,true)) then
      if (type(gCS) == 'number' or tonumber(gCS)) then
         return executeCodeLocal("CEGetScreenSize", gCS)
      end
      local limit = gCS and 3 or 1;
      local output = {}
      for i=0,limit do
         output[i+1] = executeCodeLocal("CEGetScreenSize", i)
      end
      return unpack(output)
   end
   return false
end
-- print(getScreenSize(true)) --> 2 numbers return --> 1920 1080, using true paramter will return also client size --> 1920 1080 1920 1017
local function CalculateAbsoluteCoordinateX(input,width)
   if (not (type(input)=='number' and type(width)=='number')) then
      return false
   end
   return math.floor((input * 65536) / width);
end
local function CalculateAbsoluteCoordinateY(input,height)
   if (not (type(input)=='number' and type(height)=='number')) then
      return false
   end
   return math.floor((input * 65536) / height);
end
local sMainSI = "globalalloc(CESendInput,$40)\nlabel(data)\nCESendInput:\nxor eax,eax\nmov eax,[data]\npush eax\nmov eax,[esp+8]\npush eax\nmov eax,[data+4]\npush eax\ncall SendInput\nret 4\ndata:\ndd -1\ndd -1";
function CESendInput(numberofinputs,structurePointer,structuresize) -- structuresize should be 28
   if (type(tonumber(structurePointer))~='number') then
      return false
   end
   if (autoAssembleEx(sMainSI,true)) then
      local base = getAddressEx("CESendInput",true)+0x1B
      writeIntegerLocal(base,structuresize)
      writeIntegerLocal(base+4,numberofinputs)
      local ret = executeCodeLocal("CESendInput", structurePointer)
      -- return ret;
      return ret~=0 and ret or false;
   end
   return false
end

local slMainDMC = '';
local sMainDMC = "globalalloc(CEMouseStruct,1024)\nCEMouseStruct:\ndd 0\ndd #%d\ndd #%d\ndd 0\ndd #%d\ndd 0\ndd 0"
function DoMouseClick(x,y,relative,button)
   local sW,sH = getScreenSize();
   -- LEFT DOWN = 0x0002
   -- LEFT UP = 0x0004
   -- RIGHT DOWN = 0x0008
   -- RIGHT UP = 0x0010
   local dwFlags,_x,_y = (button == 1 and bOr(0x0008,0x0010) or bOr(0x0002,0x0004))
   if (not(type(x) == 'number' and type(y) == 'number') or relative) then
      _x,_y = tonumber(x) or 0,tonumber(y) or 0;
      dwFlags = bOr(0x0001,dwFlags)
   else
      _x,_y = CalculateAbsoluteCoordinateX(x,sW),CalculateAbsoluteCoordinateY(y,sH)
      dwFlags = bOr(0x8000,bOr(0x0001,dwFlags))
   end
   local force = false;
   local sMain = sMainDMC:format(_x,_y,dwFlags)
   if (slMainDMC ~= sMain) then
      force = true;
      slMainDMC = sMain;
   end
   if (autoAssembleEx(sMain,true,force)) then
      return CESendInput(1,getAddressEx("CEMouseStruct",true),28)
   end
end


and to use it simply call
Code:

local tc = getTickCount();
for i =1,50 do
   local status = DoMouseClick(100 + (i-1)*10,150,false)
   print( status and "Clicked id -"..i or 'error failed to click') -- succeed/failed, 1.266 seconds to execute 50 clicks on my machine, can be optimized
   processMessages();
end
print(string.format("took %.4f seconds to execute",(getTickCount()-tc)/1000))


Stimulating mouse click on a different window form,by getting and adding border size, and using current window x , y which you can get from memory view or if it's cheat engine window then from cheat engine lua scripting.
Code:

f1 = createForm();
f2 = createForm();
f2.left = f1.left + math.random(200,600)
f2.top = f1.top + math.random(200,600)
b1 = createButton(f1);
b2 = createButton(f2);
b3 = createButton(f2);
b1.autosize = true;
b2.autosize = true;
b3.autosize = true;
f1.width = 200; f1.height = 200;
f2.width = 200; f2.height = 200;
b1.Top = 50; b1.left = 50; b1.Caption = "Test stimulation";
b2.Top = 50; b2.left = 50; b2.Caption = "Click id 0";
b3.Top = 100; b3.left = 50; b3.Caption = "*RANDOM WORD*";

b1.onMouseUp = function (sender)
   sender.Enabled = false;
   local wbw,wbh = getScreenSize(32),getScreenSize(12); -- getting bordersize, check msdn for more codes
   local autoClickerTimer = createTimer();
   autoClickerTimer.interval = 100;
   local i = 0;
   local created = os.clock();
   local b2top,b2left = b2.top,b2.left; -- button location relative to f2 window
   local b3top,b3left = b3.top,b3.left;
   autoClickerTimer.onTimer = function(timer)
      i = i +1;
      local mfx,mfy,mfw,mfh = f2.left,f2.top,f2.Width,f2.height -- get window x,y and width,height
      local x,y = wbw+mfx,wbh+mfy -- add window borders size;
      DoMouseClick(x+b2left+5,y+b2top+5) -- click on b2
      processMessages();
      DoMouseClick(x+b3left+5,y+b3top+5) -- click on b3
      processMessages();
      if (i >= 30) then
         processMessages();
         timer.destroy();
         sender.Enabled = true;
      end
   end
end;
--
local i = 0;
b2.onClick = function (sender)
   i = i + 1;
   sender.Caption = "Click id"..i;
end;
--
local mr,sc = math.random,string.char
b3.onClick = function (sender)
   sender.caption = "*"..sc(mr(0x41,0x5a))..sc(mr(0x41,0x5a))..sc(mr(0x41,0x5a))..sc(mr(0x41,0x5a))..sc(mr(0x41,0x5a)).."*"
end


This scripts wraps for you SendInput, so you can use it for to send mouse events, keyboard events and hardware events.

_________________
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
Twistedfate
Expert Cheater
Reputation: 1

Joined: 11 Mar 2016
Posts: 231

PostPosted: Wed Aug 24, 2016 11:51 am    Post subject: Reply with quote

Thank you very much I am gonna to study this and tells u in messages .
Ty DB too ^^ .
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