gameKeyEvents
Quick overview
Author: mud-freak
Platform: G1, G2NotR
Category: Engine, Keys
gameKeyEvents.d is a script, which handles key events with the oCGame::HandleEvent
hook. Better alternative for FrameFunction
with MEM_KeyState
with which you don't have to check whether any menu is opened or player is in dialogue or can move etc.
Author's description
I looked up the address within
oCGame::HandleEvent
. I made it into a universally usable script for Gothic 1 and Gothic 2.One could argue now that this is not much different from a
FrameFunction
withMEM_KeyState
. The difference is that this approach saves the extra work of checking if any menu is open, whether the player is in a dialog, whether the player may move, etc. Also this function is "event driven", meaning it is really only called when a key is pressed/held instead of every frame in vain. So it's arguably more performant.
Dependencies
Initialization
Call Game_KeyEventInit()
in the Init_Global()
or other initialization function.
Implementation
Usage
To add a key pressing detection edit the main function Game_KeyEvent
.
- To change detected key rename
KEY_LBRACKET
to your own key e.g. taken from Ikarus constants. - To detect pressing a key leave
(pressed)
unchanged but if you want to detect holding change it to(!pressed)
. That's becausepressed is FALSE: key is held, pressed is TRUE: key press onset
- To run code when a key is pressed, paste it or call a function where the comment is.
- To detect more than one key add
else if
.