Sign in to follow this  

How to hide mouse cursor?

This topic is 2957 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 = 1024
GameWindow.height = 768
GameWindow.maximize = false
GameWindow.size = true
GameWindow.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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 2957 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this