c# - SendInput is blocked in fruit ninja for pc -
i writing program uses sendinput
function simulate mouse events play fruit ninja pc. when called sendinput
, mouse moved nothing happened on game screen. tell me why doesn't work , give me solutions? programmed on c# , used [dllimport]
call sendinput
function. thanks.
i suggest simulating mouse move
. should simulate mouse drag
. first mouse down
-> mouse move
-> mouse up
here code old project:
namespace clicker.enums { public enum mouseevents { move = 0x0001, /* mouse move */ leftdown = 0x0002, /* left button down */ leftup = 0x0004, /* left button */ rightdown = 0x0008, /* right button down */ rightup = 0x0010, /* right button */ middledown = 0x0020, /* middle button down */ middleup = 0x0040, /* middle button */ xdown = 0x0080, /* x button down */ xup = 0x0100, /* x button down */ wheel = 0x0800, /* wheel button rolled */ virtualdesk = 0x4000, /* map entire virtual desktop */ absolute = 0x8000 /* absolute move */ } } namespace clicker.actions { public class action { protected int x; protected int y; ... [dllimport("user32")] protected static extern int setcursorpos(int x, int y); [dllimport("user32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall)] protected static extern void mouse_event(int dwflags, int dx, int dy, int cbuttons, int dwextrainfo); ... public int x { { return x; } set { x = value; } } public int y { { return y; } set { y = value; } } ... public vritual void performaction() { } ... } } namespace clicker.actions { public class drag : action { public int to_x { get; set; } public int to_y { get; set; } ... public override void performaction() { setcursorpos(x, y); thread.sleep(100); mouse_event((int)mouseevents.leftdown, 0, 0, 0, 0); setcursorpos(to_x, to_y); thread.sleep(100); mouse_event((int)mouseevents.leftup, 0, 0, 0, 0); } ... } }
using:
action slisefruit = new drag(){ x = 0, // (x=0, y=0) y = 0, // (x=0, y=0) to_x = 100, // (x=100, y=100) to_y = 100, // (x=100, y=100) }; slisefruit.performaction();
here more suggestions: issue can in synchronizationcontext
and/or threading if want click outside main form of application. possible solution:
namespace clicker.actions { public class action { protected int x; protected int y; // add fields private static synchronizationcontext _context = null; public static synchronizationcontext context { { return _context; } set { _context = value; } } ... [dllimport("user32")] protected static extern int setcursorpos(int x, int y); [dllimport("user32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall)] protected static extern void mouse_event(int dwflags, int dx, int dy, int cbuttons, int dwextrainfo); ... public int x { { return x; } set { x = value; } } public int y { { return y; } set { y = value; } } ... // ... , method internal virtual void innerperformaction(object state) { return; } // change performaction public void performaction() { innerperformaction(new object()); } ... } }
now edit drag action class:
namespace clicker.actions { public class drag : action { public int to_x { get; set; } public int to_y { get; set; } ... internal override void innerperformaction(object state) { try { context.send(new sendorpostcallback(delegate { setcursorpos(x, y); thread.sleep(100); mouse_event((int)mouseevents.leftdown, 0, 0, 0, 0); setcursorpos(to_x, to_y); thread.sleep(100); mouse_event((int)mouseevents.leftup, 0, 0, 0, 0); }), state); } catch { //aaaaahh... ever... } } ... } }
almost forgot:
// have in main form constructor action.context = synchronizationcontext.current;
i've created simple solution code, , works fine. if want can send email or something.
Comments
Post a Comment