From 755612e214fca24ce97693a941021bb3c2441479 Mon Sep 17 00:00:00 2001 From: Christoph Berganski Date: Thu, 28 Apr 2022 15:14:07 +0200 Subject: [PATCH] Enable windowed mode and raw input to get all inputs on virtual display This fixes an issue where the game does not receive most of the inputs sent to the virtual display. It is not really clear why this change is necessary, something related to the game or the X server must have changed recently... Note: Fixed some formatting along the way. --- gym_csgo/glue/keyboard.py | 6 +++--- gym_csgo/glue/mouse.py | 9 ++++++--- gym_csgo/specs/args.py | 8 +++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/gym_csgo/glue/keyboard.py b/gym_csgo/glue/keyboard.py index fb84c97..39860d1 100644 --- a/gym_csgo/glue/keyboard.py +++ b/gym_csgo/glue/keyboard.py @@ -3,7 +3,7 @@ # Sets keyboard key state -def set_key( controller, key, state ): +def set_key(controller, key, state): # If state is True (Pressed) if state: # Press the key @@ -14,7 +14,7 @@ def set_key( controller, key, state ): # Sets Counter Strike: Global Offensive keyboard key state -def control_keyboard( controller, state ): +def control_keyboard(controller, state): # Set move forward state set_key(controller, 'W', state['forward']) # Set move left state @@ -45,7 +45,7 @@ def control_keyboard( controller, state ): # Resets Counter Strike: Global Offensive keyboard key state -def reset_keyboard( controller ): +def reset_keyboard(controller): # Set move forward state set_key(controller, 'W', False) # Set move left state diff --git a/gym_csgo/glue/mouse.py b/gym_csgo/glue/mouse.py index 7d63983..01018ed 100644 --- a/gym_csgo/glue/mouse.py +++ b/gym_csgo/glue/mouse.py @@ -1,8 +1,9 @@ # Pynput library to interact with the mouse from pynput import mouse + # Sets mouse button state -def set_button( controller, button, state ): +def set_button(controller, button, state): # If state is True (Pressed) if state: # Press the mouse button @@ -11,8 +12,9 @@ def set_button( controller, button, state ): # Otherwise release the mouse button controller.release(button) + # Sets Counter Strike: Global Offensive mouse state -def control_mouse( controller, state ): +def control_mouse(controller, state): # Set special state set_button(controller, mouse.Button.right, state['special']) # Set fire state @@ -20,8 +22,9 @@ def control_mouse( controller, state ): # Move the mouse pointer (moves the game camera) controller.move(*state['camera']) + # Resets Counter Strike: Global Offensive mouse state -def reset_mouse( controller ): +def reset_mouse(controller): # Set special state set_button(controller, mouse.Button.right, False) # Set fire state diff --git a/gym_csgo/specs/args.py b/gym_csgo/specs/args.py index d4fe4ea..c772a85 100644 --- a/gym_csgo/specs/args.py +++ b/gym_csgo/specs/args.py @@ -1,4 +1,10 @@ # Essential startup arguments ESSENTIAL_ARGS = ( - '-insecure', '-untrusted', '-novid', '-nojoy', '+cl_use_opens_buy_menu', '0' + '-insecure', + '-untrusted', + '-novid', + '-nojoy', + '-windowed', '-noborder', + '+cl_use_opens_buy_menu', '0', + '+m_rawinput', '1' )