c# - Send virtual mouse clicks that are ignored by GetAsyncKeyState()? -
c# - Send virtual mouse clicks that are ignored by GetAsyncKeyState()? -
i've been experimenting , searching day, , can't life figure out how this.
as title reads, want able send mouse clicks ignored getasynckeystate().
basically i'm doing:
//while physically holding left mouse button... while (getasynckeystate(0x01) != 0) { //left mouse button virtually downwards (obviously downwards first loop) mouse_event(2, 0, 0, 0, 0); thread.sleep(100); //left mouse button virtually mouse_event(4, 0, 0, 0, 0); }
now, while-loop stops because virtually lift button, i'm asking alternative mouse_event/getasynckeystate (or parameter don't know about), can manipulate key states without affecting actual state.
for example, i've been able in autohotkey using send {lbutton up} , getkeystate("lbutton", "p").
any ideas?
msllhookstruct contains llmhf_injected
, llmhf_lower_il_injected
flags. maybe should take @ it.
the code below empty form timer, configured "on" , phone call "timerontick" every seconds.
when click, output "497, 361, 0" when timer click output "497, 361, 1"
using system; using system.diagnostics; using system.runtime.interopservices; using system.threading; using system.windows.forms; namespace syracuse { public partial class form1 : form { private const int wh_mouse_ll = 14; private static lowlevelmouseproc _proc = hookcallback; private static intptr _hookid = intptr.zero; public form1() { initializecomponent(); } protected override void onload(eventargs e) { base.onload(e); _hookid = sethook(_proc); } protected override void onclosed(eventargs e) { base.onclosed(e); unhookwindowshookex(_hookid); } private void timerontick(object sender, eventargs e) { //left mouse button virtually downwards (obviously downwards first loop) mouse_event(2, 0, 0, 0, uintptr.zero); thread.sleep(100); //left mouse button virtually mouse_event(4, 0, 0, 0, uintptr.zero); } private static intptr hookcallback(int ncode, intptr wparam, intptr lparam) { if (ncode >= 0 && mousemessages.wm_lbuttondown == (mousemessages) wparam) { var hookstruct = (msllhookstruct) marshal.ptrtostructure(lparam, typeof (msllhookstruct)); console.writeline(hookstruct.pt.x + ", " + hookstruct.pt.y + ", " + hookstruct.flags); } // todo create onmouseupexevent, onmousedownexevent witch provide msllhookstruct informations. homecoming callnexthookex(_hookid, ncode, wparam, lparam); } private static intptr sethook(lowlevelmouseproc proc) { using (var curprocess = process.getcurrentprocess()) using (var curmodule = curprocess.mainmodule) { homecoming setwindowshookex(wh_mouse_ll, proc, getmodulehandle(curmodule.modulename), 0); } } private delegate intptr lowlevelmouseproc(int ncode, intptr wparam, intptr lparam); #region enum & struct private enum mousemessages { wm_lbuttondown = 0x0201, wm_lbuttonup = 0x0202, wm_mousemove = 0x0200, wm_mousewheel = 0x020a, wm_rbuttondown = 0x0204, wm_rbuttonup = 0x0205 } [structlayout(layoutkind.sequential)] private struct msllhookstruct { public point pt; public uint mousedata; public uint flags; public uint time; public intptr dwextrainfo; } [structlayout(layoutkind.sequential)] private struct point { public int x; public int y; } #endregion #region extern [dllimport("user32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall)] public static extern void mouse_event(uint dwflags, uint dx, uint dy, uint cbuttons, uintptr dwextrainfo); [dllimport("user32.dll", charset = charset.auto, setlasterror = true)] private static extern intptr callnexthookex(intptr hhk, int ncode, intptr wparam, intptr lparam); [dllimport("kernel32.dll", charset = charset.auto, setlasterror = true)] private static extern intptr getmodulehandle(string lpmodulename); [dllimport("user32.dll", charset = charset.auto, setlasterror = true)] private static extern intptr setwindowshookex(int idhook, lowlevelmouseproc lpfn, intptr hmod, uint dwthreadid); [dllimport("user32.dll", charset = charset.auto, setlasterror = true)] [return: marshalas(unmanagedtype.bool)] private static extern bool unhookwindowshookex(intptr hhk); #endregion } }
c# windows
Comments
Post a Comment