Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

PureGDK / Question about mouse

Author
Message
Takis76
12
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 7th Feb 2012 15:54 Edited at: 7th Feb 2012 16:22
Hello again.

I have one question about mouse position.

When I have one exlusive resolution , for example 640x480
and moving my mouse arround on the corners of the screen the mouse stops at 640x0 or 0x480 or 640x480.

When I have one streched resolution , for example the same 640x480
but my desktop is 1024x768 ,then screen appears well as stretched.

But When I am moving the mouse at the corners the mouse exceeds the 640x480 and travels outside of the visible screen and stops at 1024x768 the invisible vga page or any resolution have my desktop.

I tried to trap my mouse with this function in the limits of 640x480 or any other resolution:

+ Code Snippet

The mouse was trapped in this area , but if I will press alt+tab and switch to other program or desktop the trapped area exists and is annoying for the user to have trapped his/her mouse on desktop while the game running.

Is it possible to not trap the mouse when the window of my game is inactive or I have pressed alt+tab and switched of my game and use other program?

Thank you.
Mistrel
DarkGDK Developer
12
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 7th Feb 2012 16:57 Edited at: 7th Feb 2012 16:58
Try SetCapture() and SetCursor() to make the cursor invisible if it leaves the window.

Takis76
12
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 8th Feb 2012 11:39
In fact , I don't want to make my mouse invisible , I want when I press alt+tab and switch to other program and my game runs in background , to avoid have my mouse trapped.

How do I detect if my window of my game got or lost its focus?
Mistrel
DarkGDK Developer
12
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 8th Feb 2012 15:35
GetForegroundWindow()

Takis76
12
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 9th Feb 2012 23:56 Edited at: 10th Feb 2012 00:02
Your function worked perfect.

This was an API and need one _ at the end. It took little time to realize that.

I will tell my technique.

When the game starts , after loading graphics and initialize everything put this:

+ Code Snippet

You must declare one Global integer variable as game_window.i

And in your main game loop you need to have one Procedure with the name mouse_trap().

You will call this procedure always in your gameloop.
The code of the Mouse_trap procedure:
+ Code Snippet

The mouse_trap procedure checks another one Global variable as integer with name game_active_window.i

This is the current variable before checking for the mouse trap.

If you are in your game window , the game_active_window variable always refreshes , but the game_window variable was initialized once at the beginning.

If the current game_active_window variable is equals with the beginning variable which not changes , you are in current window and the mouse_trap routine runs , else these variables are not equal
and the mouse_trap routine is not running and the mouse is not trapped when your game is running in the background.

Mistrel you are THE BEST. Thank you.

The above example was for 640x480 resolution. You can replace the numbers above with dbscreenwidth() and dbscreenheight() functions.

+ Code Snippet

And your code will run in any resolution you want.

Pointer_x and Pointer_y are another integer variables which are global too.

And you need to put this code in your game loop to update your mouse position and put it in these variables.

+ Code Snippet

These techniques worked to me and I used them in my games.

Have a nice day.
Mistrel
DarkGDK Developer
12
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 10th Feb 2012 00:29 Edited at: 10th Feb 2012 00:29
You should use the command WindowID() on the actual window created by PureBasic to get its hWnd. It's possible if you try to get it with GetForegroundWindow(), you might grab the wrong one.

Use this function to determine if the foreground window has changed, not to acquire an window handle for use.

Takis76
12
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 10th Feb 2012 00:48
You confused me a little , but my previously technique worked.
Olby
14
Years of Service
User Offline
Joined: 21st Aug 2003
Location:
Posted: 10th Feb 2012 01:36
Mistrel, suggested you change:
+ Code Snippet
to
+ Code Snippet
just replace winid with your PureBasic window number.

GetForegroundWindow_() might return incorrect handle in certain situations.

ACER Aspire 5920G: Core2Duo 2.2GHZ, 2GB, GeForce 8600M GT 1280MB, Windows Vista Ultimate SP1, PureBasic 4.60 + PureGDK 2.0
Takis76
12
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 11th Feb 2012 01:11
GetForegroundWindow_() function worked perfect.

WindowID(window) is not working well.

Returns only the current window ID , but returns the same ID even switch out window programs.

So I keep GetForegroundWindow_() function which returns any switched window handle numbers in my game.

The windowID() function returns only my game's windowID so my routine believe you don't have switched and the mouse is always trapped.

Have a nice day.

Login to post a reply

Server time is: 2017-11-22 10:58:04
Your offset time is: 2017-11-22 10:58:04