Fullscreen and the Alt+Tab thing

Just starting out? Need help? Post your questions and find answers here.
Dremth
User
User
Posts: 27
Joined: Sat Jul 10, 2004 5:24 pm
Location: My Computer
Contact:

Fullscreen and the Alt+Tab thing

Post by Dremth »

How can I make it so someone cant alt+tab out of a fullscreen window? And how can I make it so someone cant Ctrl+Alt+Delete out of the fullscreen window?

Thanks.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I really can't recommend disabling CTRL-ALT-DEL. For something like a kiosk application it's appropriate, but imho almost nowhere else. This will address the ALT-TAB issue:

Code: Select all

;========================================
; Program:    Disable ALT-TAB Demo
; Author:     netmaestro
; Date:       October 13, 2006
;
; IMPORTANT:  For the hook to work, you 
;             can't use the keyboard lib!
;             You must use API keyboard
;             handling as InitKeyboard() 
;             bypasses the hook procedure           
;========================================

hooklib = OpenLibrary(0,"AltHook.dll")
If hooklib
  keyproc=GetFunction(0, "KeyboardProc")
  KeyboardHook=SetWindowsHookEx_(#WH_KEYBOARD_LL, keyproc, hooklib, 0)
  CallFunction(0, "InitHook", KeyboardHook)
EndIf

InitSprite()
OpenScreen(1024,768,32,"")

quit=0
Repeat
  ClearScreen(#Black)
  StartDrawing(ScreenOutput())
    DrawText(420,340,"ALT-TAB is disabled, sorry!",#Green, #Black)
  StopDrawing()
  FlipBuffers()
  Delay(1)
  If GetAsyncKeyState_(#VK_ESCAPE)&32768
    quit=1
  EndIf  
Until quit

UnhookWindowsHookEx_(KeyboardHook)
Compile this code to a shared dll and make available to the demo prog:

Code: Select all

;==================================================
; Program:    Disable ALT-TAB Demo - Hook Library
; Author:     netmaestro
; Date:       October 13, 2006
;==================================================

Global KeyboardHook

CompilerIf Defined(LLKHF_ALTDOWN, #PB_Constant) = 0
  #LLKHF_ALTDOWN = $20
CompilerEndIf

CompilerIf Defined(KBDLLHOOKSTRUCT, #PB_Structure) = 0
  Structure KBDLLHOOKSTRUCT
    vkCode.l
    scanCode.l
    flags.l
    time.l
    dwExtraInfo.l
  EndStructure
CompilerEndIf

ProcedureDLL KeyboardProc(nCode,wParam,lParam)
  *keycode.KBDLLHOOKSTRUCT=lParam
  Select *keycode\vkCode
    Case #VK_TAB
      If *keycode\flags = #LLKHF_ALTDOWN
        ProcedureReturn 1
      EndIf
  EndSelect 
  ProcedureReturn CallNextHookEx_( KeyboardHook, nCode, wParam, lParam )
EndProcedure

ProcedureDLL InitHook(hookproc)
  KeyboardHook=hookproc
EndProcedure
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Fixed a bug. I can't write five lines of code without a bug. Line is changed to read:

Code: Select all

CallFunction(0, "InitHook", KeyboardHook)
There was a @ in there that didn't belong.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I can beat that; how about one line of code and 5 bugs?

:)
I may look like a mule, but I'm not a complete ass.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

And Ctrl+Alt+Del also have a twin in case some of you did not know, Ctrl+Shift+Esc

EDIT:
Oh yeah, and related to ALT+TAB there is also ALT+ESC, the windows keys, hmm what else.. a few keyboards have other special keys as well (then there are programmable ones as well)

If you intend to disable ALT+TAB for security reasons then that is the wrong way to do it, if it's not for security reasons then there should be no need to prevent it (unless your software crashes with ALT+TAB in which case fix it :P

A better way (if it's security related) is to check program window focus, and return focus to the program whenever it looses it.

Also remember that windows itself allows (on a per account basis) to disable almost anything, including Ctrl+Alt+Del/taskmanager,
this is how proper kiosk systems are setup.
Post Reply