Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8499489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:40:55+00:00 2026-06-11T00:40:55+00:00

Is it possible to get the mouse moving direction even though the mouse doesn’t

  • 0

Is it possible to get the mouse moving direction even though the mouse doesn’t move on screen? For example it collides with an edge.

edit:
The user moves the mouse to the top and collides with the top edge of the screen.
Then he keeps on moving the mouse upwards. So the mouse moves in real world but doesn’t move on the screen cause it can’t. And I want to get a signal or anything else that tells me in which direction the mouse is moving atm.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:40:56+00:00Added an answer on June 11, 2026 at 12:40 am

    As I see it, basically what you are asking is how you can detect a case where the mouse is on the edge of the screen and trying to move in the direction of the edge. Naturally, a MouseMove event will not detect this because the coordinate has not changed.

    Using a global low level mouse hook is possibly the only way of getting a mouse move message even if the cursor has not changed position.

    This allows to check if the coordinate has changed since the last message or not. If it has not, we might be at the edge of the screen.

    public partial class Form1 : Form
    {
        private const int WH_MOUSE_LL = 14;
        private const int WM_MOUSEMOVE = 0x200;
    
        [DllImport("kernel32.dll")]
        static extern IntPtr GetModuleHandle(string moduleName);
    
        [DllImport("user32.dll")]
        static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId);
    
        [DllImport("user32.dll")]
        public static extern int UnhookWindowsHookEx(IntPtr hhook);
    
        [DllImport("user32.dll")]
        static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, uint wParam, IntPtr lParam);
        delegate IntPtr HookProc(int nCode, uint wParam, IntPtr lParam);
    
        [StructLayout(LayoutKind.Sequential)]
        public struct MSLLHOOKSTRUCT
        {
            public POINT pt;
            public int mouseData; // be careful, this must be ints, not uints (was wrong before I changed it...). regards, cmew.
            public int flags;
            public int time;
            public UIntPtr dwExtraInfo;
        }
    
        [StructLayout(LayoutKind.Sequential)]
        public struct POINT
        {
            public int X;
            public int Y;
        }
    
        private HookProc hookProc;
        private IntPtr hook;
    
        private POINT formerPoint = new POINT() { X = 0, Y = 0 };
    
        public Form1() { InitializeComponent(); }
    
        IntPtr LowLevelMouseProc(int nCode, uint wParam, IntPtr lParam)
        {
            if (wParam == WM_MOUSEMOVE)
            {
                MSLLHOOKSTRUCT infoStr = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
                if (infoStr.pt.X == formerPoint.X && infoStr.pt.Y == formerPoint.Y)
                {
                    Console.WriteLine("Mouse moved without coordinates changing");
                    //use the standard way of finding the direction of travel here.
                }
                formerPoint = infoStr.pt;
            }
            return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam);
        }
    
        protected override void OnHandleDestroyed(EventArgs e)
        {
            UnhookWindowsHookEx(hook);
            base.OnHandleDestroyed(e);
        }
    
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!DesignMode)
            {
                hookProc = new HookProc(LowLevelMouseProc);
                hook = SetWindowsHookEx(WH_MOUSE_LL, hookProc, GetModuleHandle(null), 0);
            } 
        }
    }
    

    *Hook code was taken from this blog

    The problem with this method is that if the mouse is moving slower than 1 pixel per mouse message, a false positive is generated.

    A possible partial solution to this would be to pre-detect the X and Y values of screen edges and test for those as well, but even this will not eliminate 100% of false positives, as it is possible for the mouse to be (for example) on the right edge of the screen and move very slowly left (less than 1 pixel), and this would still be detected as a positive.

    Perhaps someone has a better idea how to eliminate these false positives.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it possible to get the mouse direction (Left, Right, Up, Down) based on
Possible Duplicate: How to get the mouse position without events (without moving the mouse)?
Is it possible to get the mouse position with JavaScript after page loads without
I know there is a similar question here: Moving mouse pointer on Android screen
Is it possible to get the mouse position on Silverlight, without hooking on some
Is it possible to detect mouse events from entire screen in linux? My application
Possible Duplicate: jQuery get mouse position within an element I have a page and
Is it possible to get the RGB value pixel under the mouse? Is there
Possible to get the current mouse coords with Javascript?
Just wondering if its possible to get the x/y location of the mouse from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.