Gamepad and Screensaver

BlitzMax Forums/BlitzMax Programming/Gamepad and Screensaver

When I play a game with my gamepad for awhile, the screensaver will pop-up. Unlike the keyboard or mouse, the gamepad's functions are ignored for resetting the timer to start the screensaver.

Is there a way I could prevent the screensaver from appearing when I use the gamepad or joystick?

Yes, you can prevent the screensaver from popping up. BlitzMax should probably have a way of doing this natively, but I don't think it does. You would need to write your own windows message handler, and look out for the WM_SYSCOMMAND message. When the WP data passed with a WM_SYSCOMMAND is SC_SCREENSAVER, that tells you that the system wants to run a screensaver. If your WNDProc Returns 0 when that happens, the screensaver is not allowed to start.

I'm not entirely sure what you need to do to get your own WndProc running with BlitzMax though. I do it, but I create my own window and don't use any Max2D stuff. That's the message though, so if someone can help you with setting up your own message handler, you'll know what to do with it.

EDIT: Oops, should have mentioned, this is Windows only. If you're developing on other platforms, the method used will be different.

Some old, and slightly freaky, code...
?Win32
Extern "win32"
	Function SystemParametersInfo(uiAction, uiParam, pvParam:Byte Ptr, fWinIni) = "SystemParametersInfoA@16"
End Extern

Const SPI_GETSCREENSAVEACTIVE = $10
Const SPI_SETSCREENSAVEACTIVE = $11
Const SPI_GETLOWPOWERACTIVE = $53
Const SPI_GETPOWEROFFACTIVE = $54
Const SPI_SETLOWPOWERACTIVE = $55
Const SPI_SETPOWEROFFACTIVE = $56
?

'---------------------------------- TEST ------------------------------------

Graphics 800, 600

ControlIdleResponse True
startTime = MilliSecs()

Repeat
	Cls
	
	Local hours = (MilliSecs() - startTime) / 3600000
	Local minutes = ((MilliSecs() - startTime) / 60000) Mod 60
	Local seconds = ((MilliSecs() - startTime) / 1000) Mod 60
		
	DrawText "Time Elapsed = " + hours + ":" + minutes + ":" + seconds, 320, 294
	
	'FlushMem
	
	Flip
Until KeyHit(KEY_ESCAPE)

End

'---------------------------------- TEST ------------------------------------

Function ControlIdleResponse(enable=False, powerSave=False, powerOff=False, screenSaver=False)
?Win32
	Global oldPowerSave:Byte, oldPowerOff:Byte, oldScreenSaver:Byte, first = True
	
	If enable
		If first
			SystemParametersInfo(SPI_GETLOWPOWERACTIVE, Null, Varptr(oldPowerSave), Null)
			SystemParametersInfo(SPI_GETPOWEROFFACTIVE, Null, Varptr(oldPowerOff), Null)
			SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, Null, Varptr(oldScreenSaver), Null)
			
			OnEnd ControlIdleResponseReset
			first = False
		EndIf	
	Else
		powerSave = oldPowerSave
		powerOff = oldPowerOff
		screenSaver = oldScreenSaver
	EndIf
	
	If first = False
		SystemParametersInfo(SPI_SETLOWPOWERACTIVE, powerSave, Null, Null)
		SystemParametersInfo(SPI_SETPOWEROFFACTIVE, powerOff, Null, Null)
		SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, screenSaver, Null, Null)
	EndIf
?
End Function

Function ControlIdleResponseReset()
	ControlIdleResponse False
End Function


AFAIR, the GL graphics driver dumps the screen saver messages but the DX driver doesn't.

Thanks for the code Ian! But what does "AFAIR, the GL graphics driver dumps the screen saver messages but the DX driver doesn't. " this mean?

When you use GLMax2D the screen saver (and monitor power saving?) won't kick in, whereas it will when you use DXMax2D, as you have seen.

Horribly inconsistent, I know. ;o)

So... if I were to write a screensaver using DXMax2D, the screensaver would exponentially call itself unless I came up with some code to force it to not run more than one instance?

That's ghastly. Why does it do this?

I'm almost certain that an NT based OS won't start a screen saver once another is already running. Under Win98, this would happen, although it wouldn't be exponential as the system invokes the saver, not the saver itself.

I don't like the idea of the GL graphics driver silently dumping the screen saver messages and would prefer it to be, at the very least, optional. There may be times that you'd want a graphical app to be sitting in the background.

Ideally, there'd be built in commands to control this behaviour for GL *and* DX, possibly with the default being to suppress any screen saver and/or power saving.


I haven't got a clue what happens under Linux and OSX. :o/

I'm almost certain that an NT based OS won't start a screen saver once another is already running
Well, that being the case its not quite as catastrophic as I thought it was. But even so, one type of behaviour in DX and something different under GL is confusing at best. They should both be the same and I can't think of any logical reason why they aren't.

I haven't got a clue what happens under Linux and OSX. :o/
At this point in time, I don't much care. But I'm sure its something that needs looking at.

But even so, one type of behaviour in DX and something different under GL is confusing at best. They should both be the same and I can't think of any logical reason why they aren't.
Can't argue with that. :o)