Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Lock the mouse to my application

Lock the mouse to my application

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 808778
    wrote on last edited by
    #1

    Hi! I want to lock the mouse to my application with a key-combination. By lock I mean in a way that you can't move the mouse outside the window of my application. I want to unlock the mouse with the same key-combination (e.g. Ctrl+l). Is that possible? Can anyone help he? Thanks Erik

    H 1 Reply Last reply
    0
    • U User 808778

      Hi! I want to lock the mouse to my application with a key-combination. By lock I mean in a way that you can't move the mouse outside the window of my application. I want to unlock the mouse with the same key-combination (e.g. Ctrl+l). Is that possible? Can anyone help he? Thanks Erik

      H Offline
      H Offline
      Hesham Amin
      wrote on last edited by
      #2

      Hi you need to call ClipCursor API

      BOOL ClipCursor(
      CONST RECT *lpRect // screen coordinates
      );

      check MSDN for more info.

      O 1 Reply Last reply
      0
      • H Hesham Amin

        Hi you need to call ClipCursor API

        BOOL ClipCursor(
        CONST RECT *lpRect // screen coordinates
        );

        check MSDN for more info.

        O Offline
        O Offline
        osto
        wrote on last edited by
        #3

        i thought this was a big developer NO-NO!:mad:

        H 1 Reply Last reply
        0
        • O osto

          i thought this was a big developer NO-NO!:mad:

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Actually, just use the Cursor.Clip property already provided in the .NET FCL. As far as being a no-no, just make sure you restore the clipping region (the desktop area) after you're done - even in case of error.

          Microsoft MVP, Visual C# My Articles

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups