Page 1 of 1

Fullscreen and the Alt+Tab thing

Posted: Thu Oct 12, 2006 11:34 pm
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.

Posted: Fri Oct 13, 2006 5:50 am
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

Posted: Fri Oct 13, 2006 8:21 am
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.

Posted: Fri Oct 13, 2006 8:56 am
by srod
I can beat that; how about one line of code and 5 bugs?

:)

Posted: Sat Oct 14, 2006 1:41 am
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.