Mouse at screen corner activates functions...

Share your advanced PureBasic knowledge/code with the community.
User avatar
Michael Vogel
Addict
Addict
Posts: 2810
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Mouse at screen corner activates functions...

Post by Michael Vogel »

Just a simple code to start some window functions when you move your mouse to a screen corner...

Code: Select all

#MausTrigger=30

Global sx=GetSystemMetrics_(#SM_CXSCREEN)
Global sy=GetSystemMetrics_(#SM_CYSCREEN)

Global Mausi.q
Global Mecki.l

Enumeration
	#Idle
	#TopLeft
	#TopRight
	#BottomLeft
	#BottomRight
EndEnumeration

Procedure MausArnie(corner)

	If Mecki=#MausTrigger

		Select corner
		Case #TopLeft
			PostMessage_(GetForegroundWindow_(),#WM_SYSCOMMAND,#SC_SCREENSAVE,0)
		Case #TopRight
			Debug "TopRight"
		Case #BottomLeft
			Debug "BottomLeft"
		Case #BottomRight
			Debug "BottomRight"
		EndSelect

	EndIf
	Mecki+1

EndProcedure



Repeat

	Delay(10)
	GetCursorPos_(@Mausi)

	If Mausi=0
		MausArnie(#TopLeft)

	ElseIf Mausi=sx-1
		MausArnie(#TopRight)

	ElseIf Mausi=(sy-1)<<32
		MausArnie(#BottomLeft)

	ElseIf Mausi=(sy-1)<<32+sx-1
		MausArnie(#BottomRight)

	Else
		Mecki=#False
	EndIf

Until GetAsyncKeyState_(#VK_SPACE)
I started with activating the screen saver, but now some cool ideas are needed what to do at the four positions...
...what about maximizing (or minimizing) the active window?
...or hiding/showing all windows (like using the shortcut Windows-D)?
...or something completely different?

Michael
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Neat, one question though:

Why use GetSystemMetrics and not the PB-Built-In Desktop Functions?

Besides, on a dual (pick your own amount...) monitor setup handling is weird because a corner of the main screen could be in the middle of the total desktop space.
Suppose this is a general problem of this type of programs...

bye
fsw
User avatar
Michael Vogel
Addict
Addict
Posts: 2810
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

fsw wrote:[...]Besides, on a dual (pick your own amount...) monitor setup handling is weird because a corner of the main screen could be in the middle of the total desktop space.
[...]
Hm,
seems to be something like a logical puzzle to find out wich are the coordinates of the "real" four corners...
...will think about that :?

Another point is, I tried to find some nice functions for using this tools, but I failed to realize some ideas...
• put active window to the back (z-order)
• minimize all windows but active
• simulate Windows+D

...other functions could be done, but are not very useful, like...

Code: Select all

	handle=GetForegroundWindow_()
	If IsIconic_(handle)
		PostMessage_(GetForegroundWindow_(),#WM_SYSCOMMAND,#SC_RESTORE,0)
	Else
		ShowWindow_(handle,#SW_SHOWMINNOACTIVE)
	EndIf
Any further ideas?


Here's the actual version which has the following functions:
TL - activate screen saver (works :D)
TR - minimize active (but not topmost :cry:) window
BL - moves active window to the background, should activate the next ( also not so perfect :x)
BR - restores first minimized window (seems to work :))

Code: Select all

#MausTrigger=16

Global sx=GetSystemMetrics_(#SM_CXSCREEN)
Global sy=GetSystemMetrics_(#SM_CYSCREEN)

Global Mausi.q
Global Mecki.l

Enumeration
	#Idle
	#TopLeft
	#TopRight
	#BottomLeft
	#BottomRight
EndEnumeration

Procedure RestoreMinimizedWindow(handle,dummy)
	If IsIconic_(handle)
		PostMessage_(handle,#WM_SYSCOMMAND,#SC_RESTORE,0)
		ProcedureReturn #False
	EndIf
	ProcedureReturn #True
EndProcedure

Procedure MausArnie(corner)

	Protected handle=GetForegroundWindow_()
	;handle=GetActiveWindow_()
	;handle=GetTopWindow_(0)


	If Mecki=#MausTrigger

		Select corner
		Case #TopLeft
			PostMessage_(handle,#WM_SYSCOMMAND,#SC_SCREENSAVE,0)

		Case #TopRight
			ShowWindow_(handle,#SW_MINIMIZE)

		Case #BottomLeft
			SetWindowPos_(handle,#HWND_BOTTOM,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE|#SWP_NOACTIVATE)
			handle=GetTopWindow_(0)
			SetActiveWindow_(handle)

		Case #BottomRight
			EnumWindows_(@RestoreMinimizedWindow(),1)
		EndSelect

	EndIf
	Mecki+1

EndProcedure



Repeat

	Delay(10)
	GetCursorPos_(@Mausi)

	If Mausi=0
		MausArnie(#TopLeft)

	ElseIf Mausi=sx-1
		MausArnie(#TopRight)

	ElseIf Mausi=(sy-1)<<32
		MausArnie(#BottomLeft)

	ElseIf Mausi=(sy-1)<<32+sx-1
		MausArnie(#BottomRight)

	Else
		Mecki=#False
	EndIf

Until GetAsyncKeyState_(#VK_SPACE)
User avatar
Michael Vogel
Addict
Addict
Posts: 2810
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

New (slightly improved) functions for the screen corners:

Code: Select all

Procedure MausArnie(corner)

	Protected  dummy
	Protected handle=GetForegroundWindow_()

	dummy=GetParent_(handle)
	If dummy
		handle=dummy
	EndIf

	If Mecki=#MausTrigger

		Select corner
		Case #TopLeft
			PostMessage_(handle,#WM_SYSCOMMAND,#SC_SCREENSAVE,0)

		Case #TopRight
			EnumWindows_(@RestoreMinimizedWindow(),1)

		Case #BottomLeft
			keybd_event_(#VK_RWIN,0,#KEYEVENTF_KEYUP,0)
			keybd_event_(#VK_LWIN,0,0,0)
			keybd_event_(#VK_D,0,0,0)
			keybd_event_(#VK_LWIN,0,#KEYEVENTF_KEYUP,0)
			keybd_event_(#VK_D,0,#KEYEVENTF_KEYUP,0)

		Case #BottomRight
			;Debug handle
			ShowWindow_(handle,#SW_MINIMIZE)

		EndSelect

	EndIf
	Mecki+1

EndProcedure
Post Reply