diff --git a/engine/key_modifiers.h b/engine/key_modifiers.h new file mode 100644 index 00000000..a07e1829 --- /dev/null +++ b/engine/key_modifiers.h @@ -0,0 +1,35 @@ +/* +key_modifiers.h - enumeration of possible key modifiers +Copyright (C) 2022 FWGS Team + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +*/ + +#pragma once +#ifndef KEY_MODIFIERS_H +#define KEY_MODIFIERS_H + +typedef enum +{ + KeyModifier_None = 0, + KeyModifier_LeftShift = (1 << 0), + KeyModifier_RightShift = (1 << 1), + KeyModifier_LeftCtrl = (1 << 2), + KeyModifier_RightCtrl = (1 << 3), + KeyModifier_LeftAlt = (1 << 4), + KeyModifier_RightAlt = (1 << 5), + KeyModifier_LeftSuper = (1 << 6), + KeyModifier_RightSuper = (1 << 7), + KeyModifier_NumLock = (1 << 8), + KeyModifier_CapsLock = (1 << 9) +} key_modifier_t; + +#endif diff --git a/engine/platform/platform.h b/engine/platform/platform.h index 02645265..a353f407 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -21,6 +21,7 @@ GNU General Public License for more details. #include "system.h" #include "defaults.h" #include "cursor_type.h" +#include "key_modifiers.h" /* ============================================================================== @@ -73,6 +74,7 @@ void*Platform_GetNativeObject( const char *name ); int Platform_JoyInit( int numjoy ); // returns number of connected gamepads, negative if error // Text input void Platform_EnableTextInput( qboolean enable ); +key_modifier_t Platform_GetKeyModifiers( void ); // System events void Platform_RunEvents( void ); // Mouse diff --git a/engine/platform/sdl/in_sdl.c b/engine/platform/sdl/in_sdl.c index dec29ed1..1d1a19fe 100644 --- a/engine/platform/sdl/in_sdl.c +++ b/engine/platform/sdl/in_sdl.c @@ -323,4 +323,41 @@ void Platform_SetCursorType( cursor_type_t type ) #endif } +/* +======================== +Platform_GetKeyModifiers + +======================== +*/ +key_modifier_t Platform_GetKeyModifiers( void ) +{ + SDL_Keymod modFlags; + key_modifier_t resultFlags; + + resultFlags = KeyModifier_None; + modFlags = SDL_GetModState(); + if( FBitSet( modFlags, KMOD_LCTRL )) + SetBits( resultFlags, KeyModifier_LeftCtrl ); + if( FBitSet( modFlags, KMOD_RCTRL )) + SetBits( resultFlags, KeyModifier_RightCtrl ); + if( FBitSet( modFlags, KMOD_RSHIFT )) + SetBits( resultFlags, KeyModifier_RightShift ); + if( FBitSet( modFlags, KMOD_LSHIFT )) + SetBits( resultFlags, KeyModifier_LeftShift ); + if( FBitSet( modFlags, KMOD_LALT )) + SetBits( resultFlags, KeyModifier_LeftAlt ); + if( FBitSet( modFlags, KMOD_RALT )) + SetBits( resultFlags, KeyModifier_RightAlt ); + if( FBitSet( modFlags, KMOD_NUM )) + SetBits( resultFlags, KeyModifier_NumLock ); + if( FBitSet( modFlags, KMOD_CAPS )) + SetBits( resultFlags, KeyModifier_CapsLock ); + if( FBitSet( modFlags, KMOD_RGUI )) + SetBits( resultFlags, KeyModifier_RightSuper ); + if( FBitSet( modFlags, KMOD_LGUI )) + SetBits( resultFlags, KeyModifier_LeftSuper ); + + return resultFlags; +} + #endif // XASH_DEDICATED