Skip to main content
GameDev.net gamedev.net
🔒 Locked

How to hide mouse cursor?

Started by CodaKiller Nov 6, 2009 at 5:39 PM 17 replies 4.2k views
Original Post
CodaKiller
CodaKiller
This is more complex then the average problem of hiding the mouse cursor, I have no window to hide the mouse with, how can I hide it on a global scale?
Remember Codeka is my alternate account, just remember that!
CodaKiller
CodaKiller
Quote:
Original post by snake5
It doesn't sound like anything that a game should do.. why do you need that?


My game engine has programmable windows and there is not always going to be a window to hide the mouse cursor.
Remember Codeka is my alternate account, just remember that!
CodaKiller
CodaKiller
Quote:
Original post by ApochPiQ
I assume you've already tried ShowCursor with unsatisfactory results?


Only works over a window owned by the instance of the application.
Remember Codeka is my alternate account, just remember that!
Erik Rufelt
Erik Rufelt
You're not really supposed to hide the cursor anywhere else. Your program is the window, and outside of it the user might have other programs you shouldn't mess with. I assume you're only drawing inside your window, so why would you hide the cursor anywhere else?
ApochPiQ
ApochPiQ
It's bad etiquette to hide the cursor over windows you don't own.

I also don't see how having "programmable" windows causes issues; if there's no window for your app, then why do you need to be hiding the cursor?

Maybe if you start from the top and explain what you're trying to accomplish we can figure out a solution that works and is polite to other software.
Wan
Wan
Not to be pedantic, but if possible, you might at least want to ensure that the cursor is restored in case of a program crash. You don't want to leave your users with a mouseless operating system.
CodaKiller
CodaKiller
Quote:
Original post by ApochPiQ
It's bad etiquette to hide the cursor over windows you don't own.

I also don't see how having "programmable" windows causes issues; if there's no window for your app, then why do you need to be hiding the cursor?

Maybe if you start from the top and explain what you're trying to accomplish we can figure out a solution that works and is polite to other software.


In my game engine I have a window class which is used in a script to create windows, example:

GameWindow = create_window()GameWindow.title = "Game Demo"GameWindow.width = 1024GameWindow.height = 768GameWindow.maximize = falseGameWindow.size = trueGameWindow.icon = "Default.ico"GameWindow.show_cursor = false



I've made it so that the window class can hide the cursor when it is over the window, I can set some windows to show the cursor and others to hide it.

This is a useful feature but when I am trying to control the camera for a 3D game it lets the mouse move freely around and if the user clicks to fire a weapon it could for instance click My computer or something and open a window while the player is playing.

This is unacceptable, I can create a function which binds the mouse to a window but I would prefer to just disable the cursor altogether and enable it when the program closes or when focus is changed to another application.

I'm not sure if there is a way to do this so that the cursor will always return even if the program crashes or if this can be done at all.
Remember Codeka is my alternate account, just remember that!
Erik Rufelt
Erik Rufelt
Hiding the cursor does nothing for this problem, as even if the cursor is hidden, clicks still work. Somehow disabling mouse clicks would be a very bad idea and probably wouldn't reset itself if your program crashed, or if you fail to handle switching programs correctly. Constrain the mouse to your window instead, as all other games do. It is an easier and a better solution.
mattd
mattd
Quote:
Original post by CodaKiller
I can create a function which binds the mouse to a window

This is want you want to do. Use ClipCursor. And read the Remarks section! :)

Quote:
but I would prefer to just disable the cursor altogether and enable it when the program closes or when focus is changed to another application.

You can't disable the cursor outright, and even if you managed to hide it globally, it still wouldn't stop it from giving input to other applications, i.e., click events.
CodaKiller
CodaKiller
I have a crazy idea that may just work, what if I were to create a small transparent window and clip the cursor to it?
Remember Codeka is my alternate account, just remember that!
Erik Rufelt
Erik Rufelt
I have an even crazier one, what if you were to just not mess with the cursor, unless you have a proper window to clip it to. =)
mattd
mattd
If you're trying to implement mouselook, the typical method is: upon receiving a WM_MOUSEMOVE message (or however you are notified of cursor movement over your window), calculate the cursor's deviation from the centre of your window, and then move the cursor back to that same centre.

You typically also call ShowCursor to hide the cursor while it's over your window, so it doesn't sit in the way of your crosshairs or whatever.

Combined with ClipCursor, you can be sure the cursor won't go outside of your window.

You only do this when your application is in focus, so users can ALT-TAB out (or perhaps if you can pause the game, or show a menu, you relinquish control of the cursor.)

By keeping the mouse in the centre of your application window, you get deltas which you can use to rotate your camera, while keeping the mouse cursor under control.
Icebone1000
Icebone1000
Maybe that is offtopic, but I remember some time ago when ZSNES crashed here in my pc, so I pressed ctrlaltdel, and got a weird stuff:
The mouse was still moving, and showing, like normal, but clicks wasnt working! Very weird and annoing, most terrible was that ZSNES was using 100% CPU and I didnt achieve to kill the ZSNES without the mouse! Yeah, sounds lame, but I still dont know how to kill a process on the task manager without the mouse, I didnt find any button to do the job...-__- lame...

>_> I pushed reset..

How can the cursor stop clicking?
mattd
mattd
Quote:
Original post by Icebone1000
Yeah, sounds lame, but I still dont know how to kill a process on the task manager without the mouse, I didnt find any button to do the job...-__- lame...

You can press DELETE to kill the highlighted process.

Quote:
How can the cursor stop clicking?

Never underestimate what can happen when you misuse the Win32 API :)

CodaKiller
CodaKiller
BTW I thought I would update you guys, my idea works fine, see for yourself: link
Remember Codeka is my alternate account, just remember that!
Icebone1000
Icebone1000
Quote:

You can press DELETE to kill the highlighted process.


Not to me(win2000), delete doesnt do anything here..
benryves
benryves
Quote:
Original post by Icebone1000
Quote:

You can press DELETE to kill the highlighted process.


Not to me(win2000), delete doesnt do anything here..
Alt+E (note the underlined E on End Task). (May be different in Portuguese, if you're using a Portuguese copy of Windows). Alternatively, press the application key and select an item from the drop-down menu.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.