Extrawindow - No event from mouse and keyboard
Posted: Wed Aug 06, 2014 4:17 pm
Heyho,
I discovered a mysterious Thing by testing my program. If an other window then your window with WindowedScreen is active (got Focus), you can´t receive Keyboard- and mouseevents. Ok, seems correct (By the way, I don´t want it like this...). But this rule isn´t valid for Joysticks/Gamepads. You can still catch those gamepadevents.
But why is this realised this way? Why we can´t get Events everytime like gamepadevents?
In my case, I implemented Options for custom control. This is in an extra Windows window, but this way I can´t get Keyboard and Mouseevents. I think I have to use CGUI.
Here´s a code for testing:
I discovered a mysterious Thing by testing my program. If an other window then your window with WindowedScreen is active (got Focus), you can´t receive Keyboard- and mouseevents. Ok, seems correct (By the way, I don´t want it like this...). But this rule isn´t valid for Joysticks/Gamepads. You can still catch those gamepadevents.
But why is this realised this way? Why we can´t get Events everytime like gamepadevents?
In my case, I implemented Options for custom control. This is in an extra Windows window, but this way I can´t get Keyboard and Mouseevents. I think I have to use CGUI.
Here´s a code for testing:
Code: Select all
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>> >>
;>> Name: Keyboardtest >>
;>> >>
;>> Author: Bananenfreak >>
;>> >>
;>> Date: 06.08.2014 >>
;>> >>
;>> OS: Windows >>
;>> >>
;>> >>
;>> >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
EnableExplicit
Define.f KeyX, KeyY, MouseX, MouseY
Define nx.f, nz.f, Boost.f = 1, Yaw.f, Pitch.f
Define.i Quit, boden, gamepad
#kam_0 = 0
#window = 0
#plane = 0
#planent = 0
#N2 = 1
If InitEngine3D()
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
gamepad = InitJoystick()
If gamepad = 0
Debug "No gamepad..."
End
EndIf
OpenWindow(#window, 0, 0, 1800, 1000, "Keyboardtest", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#window), 10, 10, 2000, 2000, 0, 10, 10, #PB_Screen_SmartSynchronization)
WorldShadows(#PB_Shadow_TextureAdditive, 200, RGB(255 * 0.2, 255 * 0.2, 255 * 0.2), 4096)
AmbientColor(RGB(255 * 0.2, 255 * 0.2, 255 * 0.2))
CreatePlane(#plane, 100, 100, 100, 100, 100, 100)
boden = GetScriptMaterial(#PB_Any, "Scene/GroundBlend")
CreateEntity(#planent, MeshID(#plane), MaterialID(boden), 0, 0, 0)
;-Camera
CreateCamera(#kam_0, 0, 0, 100, 100)
MoveCamera(#kam_0, 0, 20, 0, #PB_Absolute)
CameraLookAt(#kam_0, 20, 0, 20)
CameraRange (#kam_0, 2, 5000)
CameraFOV (#kam_0, 90)
CameraBackColor(#kam_0, RGB(0, 0, 0))
OpenWindow(#N2, 100, 100, 100, 100,"Test2")
Repeat
ExamineJoystick(0)
Repeat
Until WindowEvent() = 0
If ExamineMouse()
Yaw = -MouseDeltaX() * 0.05
Pitch = -MouseDeltaY() * 0.05
If MouseButton(#PB_MouseButton_Left)
Debug "Mouse"
EndIf
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
MoveCamera(0, 0, 0, -1 * Boost)
ElseIf KeyboardPushed(#PB_Key_Down)
MoveCamera(0, 0, 0, 1 * Boost)
EndIf
If KeyboardPushed(#PB_Key_Left)
MoveCamera(0, -1 * Boost, 0, 0)
ElseIf KeyboardPushed(#PB_Key_Right)
MoveCamera(0, 1 * Boost, 0, 0)
EndIf
If KeyboardPushed(#PB_Key_W)
Debug "Key W"
EndIf
EndIf
If JoystickButton(0, 1)
Debug "Gamepad!"
EndIf
RotateCamera(0, Pitch, Yaw, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End