C++hook Global Touch Events

Source: Internet
Author: User

https://gist.github.com/vbfox/1339671

namespaceblackfox{usingSystem; usingSystem.ComponentModel; usingSystem.Runtime.InteropServices; usingSystem.Security; /// <summary>    ///As long as this object exists all mouse events created from a touch event for legacy support would be disabled. /// </summary>    classdisabletouchconversiontomouse:idisposable {Static ReadOnlyLowlevelmouseproc Hookcallback =Hookcallback; StaticIntPtr Hookid =IntPtr.Zero;  PublicDisabletouchconversiontomouse () {Hookid=sethook (Hookcallback); }        StaticIntPtr sethook (lowlevelmouseproc proc) {varModulehandle = Unsafenativemethods.getmodulehandle (NULL); varSethookresult = Unsafenativemethods.setwindowshookex (Wh_mouse_ll, Proc, Modulehandle,0); if(Sethookresult = =IntPtr.Zero) {Throw Newwin32exception (); }            returnSethookresult; }        DelegateIntPtr Lowlevelmouseproc (intNCode, IntPtr WParam, IntPtr lParam); StaticIntPtr Hookcallback (intNCode, IntPtr WParam, IntPtr LParam) {            if(NCode >=0)            {                varinfo = (msllhookstruct) marshal.ptrtostructure (LParam,typeof(msllhookstruct)); varExtraInfo = (UINT) Info.dwExtraInfo.ToInt32 (); if((ExtraInfo & mouseeventf_fromtouch) = =Mouseeventf_fromtouch) {                    return NewINTPTR (1); }            }            returnUnsafenativemethods.callnexthookex (Hookid, NCode, WParam, LParam); }                BOOLdisposed;  Public voidDispose () {if(disposed)return;            Unsafenativemethods.unhookwindowshookex (Hookid); Disposed=true; Gc. SuppressFinalize ( This); }        ~Disabletouchconversiontomouse () {Dispose (); }        #regionInterop//ReSharper Disable inconsistentnaming//ReSharper Disable membercanbeprivate.local//ReSharper Disable fieldcanbemadereadonly.local        Const UINTMouseeventf_fromtouch =0xff515700; Const intWh_mouse_ll = -; [StructLayout (layoutkind.sequential)]structPoint { Public intx;  Public inty; } [StructLayout (layoutkind.sequential)]structmsllhookstruct { PublicPoint pt;  Public UINTMousedata;  Public UINTflags;  Public UINTTime ;  PublicIntPtr dwExtraInfo; } [SuppressUnmanagedCodeSecurity]Static classUnsafeNativeMethods {[DllImport ("user32.dll", CharSet = CharSet.Auto, SetLastError =true)]             Public Static externIntPtr SetWindowsHookEx (intIdhook, Lowlevelmouseproc lpfn, IntPtr hmod,UINTdwThreadID); [DllImport ("user32.dll", CharSet = CharSet.Auto, SetLastError =true)]            [return: MarshalAs (unmanagedtype.bool)] Public Static extern BOOLUnhookWindowsHookEx (IntPtr hhk); [DllImport ("user32.dll", CharSet = CharSet.Auto, SetLastError =true)]             Public Static externIntPtr CallNextHookEx (IntPtr hhk,intNCode, IntPtr WParam, IntPtr lParam); [DllImport ("Kernel32.dll", CharSet = CharSet.Auto, SetLastError =true)]             Public Static externIntPtr GetModuleHandle (stringlpmodulename); }        //ReSharper Restore Inconsistentnaming//ReSharper Restore Fieldcanbemadereadonly.local//ReSharper Restore Membercanbeprivate.local        #endregion    }}

C++hook Global Touch Events

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.