Enable/Disable Exclusive Keyboard Mode with InitKeyboard()
Posted: Sat Dec 10, 2005 8:35 am
hi fred,
setting the keyboard to exclusive mode, while using InitKeyboard() can be a nice thing, but also a huge barrier. especially with OpenWindowedScreen() instead of OpenScreen().
almost the whole system keys wont work and this can be a real pain in some situations. even if you can rebuild (almost) every system key function, there are still some missing parts, which simply cant be rebuild.
it would be nice to have a function to switch to exclusive mode and switch back to normal mode anytime. something similar to KeyboardMode() would be great. maybe a KeyboardExclusive().
like this code by stefan from german forum:
but the problem here is, after taskswitching the exclusive keyboard mode is set again, so you have to check every time if the application was inactive and become active again to set non exclusive keyboard mode again. which would be a little bit ugly imho.
so an optional parameter for InitKeyboard(Exclusive #True/#False) would be also nice. the best way would be, to have them both, i guess:
oh and btw, thanks for KeyboardMode() this is a great thing, for german keyboards.
c ya,
nco2k
setting the keyboard to exclusive mode, while using InitKeyboard() can be a nice thing, but also a huge barrier. especially with OpenWindowedScreen() instead of OpenScreen().
almost the whole system keys wont work and this can be a real pain in some situations. even if you can rebuild (almost) every system key function, there are still some missing parts, which simply cant be rebuild.
it would be nice to have a function to switch to exclusive mode and switch back to normal mode anytime. something similar to KeyboardMode() would be great. maybe a KeyboardExclusive().

like this code by stefan from german forum:
Code: Select all
#DISCL_BACKGROUND=8
#DISCL_NONEXCLUSIVE=2
#DISCL_EXCLUSIVE=1
#DISCL_FOREGROUND=4
Procedure GetDInputDevice();Returns the DirectInputDevice of the Keyboard.
Global *_DirectInput7A.IDirectInput7A
Global *_DirectInputDevice7A.IDirectInputDevice7A
!extrn _PB_DirectInput
!extrn _PB_Keyboard_InitState
!CMP dword[_PB_Keyboard_InitState],0
!JNZ InitStateOk
ProcedureReturn 0
!InitStateOk:
!MOV Eax,[_PB_DirectInput]
!MOV [p__DirectInput7A],Eax
If *_DirectInput7A\CreateDevice(?KeyboardGUID,@*DID2.IDirectInputDevice7A,0):ProcedureReturn 0:EndIf
Table=PeekL(*DID2)+OffsetOf(IDirectInputDevice7A\GetDeviceState())
ReadProcessMemory_(GetCurrentProcess_(),Table,@GetDevState,4,@dummy)
Fake=?Fake
WriteProcessMemory_(GetCurrentProcess_(),Table,@Fake,4,@dummy)
ExamineKeyboard()
WriteProcessMemory_(GetCurrentProcess_(),Table,@GetDevState,4,@dummy)
*DID2\Release()
ProcedureReturn *_DirectInputDevice7A
InitKeyboard()
Fake:
!MOV Eax,[Esp+4]
!MOV [p__DirectInputDevice7A],Eax
!XOR Eax,Eax
!RET 12
DataSection
KeyboardGUID:
Data.l 1864182625,298833312,1162135487,21587
EndDataSection
EndProcedure
Procedure SwapToNonExclusiveKeyboard()
*Dev.IDirectInputDevice7A=GetDInputDevice()
*Dev\UnAcquire()
*Dev\SetCooperativeLevel(ScreenID(),#DISCL_NONEXCLUSIVE|#DISCL_FOREGROUND)
*Dev\Acquire()
EndProcedure
InitSprite()
InitKeyboard()
If OpenWindow(0, 0, 0, 800, 600, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "") = 0 : End : EndIf
If OpenWindowedScreen(WindowID(), 0, 20, 800, 600, 1, 0, 0) = 0 : End : EndIf
SwapToNonExclusiveKeyboard(); Muss nach OpenWindowedScreen() ausgeführt werden.
If CreateMenu(0,WindowID())
MenuTitle("&x")
MenuItem(0, "&y")
MenuItem(1, "&z")
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
Select EventMenuID()
Case 0
;...
;..
;.
EndSelect
EndSelect
ExamineKeyboard() ;ohne gehts
Until KeyboardPushed(#PB_Key_Escape)
so an optional parameter for InitKeyboard(Exclusive #True/#False) would be also nice. the best way would be, to have them both, i guess:
Code: Select all
InitKeyboard(Exclusive) ;#True/#False
KeyboardExclusive(Exclusive) ;#True/#False

c ya,
nco2k