Code archives/BlitzPlus Gui/Disable Alt+Tab Easily

This code has been declared by its author to be Public Domain code.

Download source code

Disable Alt+Tab Easily by SebHoll
(Posted 21 years ago)
This code disables Alt+Tab while the program is running by assigning the "Alt+Tab" sequence a HotKey property for your window. E.g. your window snatches the "Alt+Tab" key presses from the O/S. LOL.

Dead easy to use - just make sure that you use UnRegisterHotKey() once app has finished otherwise some users may not be able to regain "Alt+Tab" functionality when program closes.

.lib "user32.dll"
RegisterHotKey%(hwnd%,id%,modifiers%,virtualkey%)
UnregisterHotKey%(hwnd%,id%)
The "100" specified as ID for the hotkey could be anything I think but I know 100 works so best to stick with that.

I have tried to change this script to block the "Windows Key" also to no avail.

Hope this helps someone out there...
wndMain = CreateWindow("Hello",100,100,400,300,0,1)
hwnd = QueryObject(wndMain,1)

RegisterHotKey(hwnd,100,$1,$9)	;Alt Tab

Repeat

event = WaitEvent()

Select event

	Case $803
	UnregisterHotKey(hwnd,100)
	End
	
End Select

Forever

Comments

big10p
(Posted 21 years ago)
What happens if my app crashes before it can execute UnRegisterHotKey?

SebHoll
(Posted 21 years ago)
On my Win XP Pro computer it automatically removes the hot key but I thought that it was good practice to put it in as it may not do so on Win 98/NE etc. On my XP computer though, there's no problem!!!

big10p
(Posted 21 years ago)
I've got a win98SE machine so I might give this a try, if I'm feeling brave. Just don't want to fubar my system, if I can help it. :) Thanks.

SebHoll
(Posted 21 years ago)
OK - Thanks Chris. I think it should work and if not, restarting the system should remove all "HotKey" assignments.

big10p
(Posted 21 years ago)
OK, I tried this on my win98SE machine in blitz3D using:
hwnd = SystemProperty("AppHWND")
RegisterHotKey(hwnd,100,$1,$9) ;Alt Tab
	
.
.
.
	
UnregisterHotKey(hwnd,100)


But it doesn't work. :( Disabling alt+tab on win98 machines seems to be a real pain, by all accounts.

Grey Alien
(Posted 21 years ago)
Try BlackJumper's StickyKey.dll it does otherstuff AND removes Alt+Tab.

big10p
(Posted 21 years ago)
I tested for BlackJumper in the past to try and get it to work on win98 - no joy. He's going to have another go at some point, though.

Perturbatio
(Posted 21 years ago)
for win98: http://support.microsoft.com/kb/226359/en-us/

BlackJumper
(Posted 21 years ago)
For a related thread on detecting Alt+TAB and other ways to lose focus see Eikon and Grey Alien's work on this thread

Code Archives Forum