#include "ASW.h" const char * ASW::Input::m_ptrKeys[ASW::Input::KEY_COUNT] = { "ESCAPE", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "PRNTSCN", "SCRLCK", "PAUSE", "ACCENT", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "MINUS", "EQUALS", "BACKSPACE", "INSERT", "HOME", "PAGEUP", "KEYPAD_NUMLOCK", "KEYPAD_DIVIDE", "KEYPAD_MULTIPLY", "KEYPAD_SUBTRACT", "TAB", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "BRACKETL", "BRACKETR", "BACKSLASH", "DELETE", "END", "PAGEDOWN", "KEYPAD_7", "KEYPAD_8", "KEYPAD_9", "KEYPAD_ADD", "CAPSLOCK", "A", "S", "D", "F", "G", "H", "J", "K", "L", "SEMICOLON", "QUOTE", "ENTER", "KEYPAD_4", "KEYPAD_5", "KEYPAD_6", "SHIFTL", "Z", "X", "C", "V", "B", "N", "M", "COMMA", "PERIOD", "FORWARDSLASH", "SHIFTR", "UP", "KEYPAD_1", "KEYPAD_2", "KEYPAD_3", "KEYPAD_ENTER", "CONTROLL", "WINDOWSL", "ALTL", "SPACE", "ALTR", "WINDOWSR", "CONTROLR", "LEFT", "DOWN", "RIGHT", "KEYPAD_0", "KEYPAD_PERIOD", "MB0", "MB1", "MB2", "MB3", "MB4", "MB5", "MB6", "MB7", }; ASW::Input:: Input() { memset(&m_blnKeys, 0, ASW::Input::KEY_COUNT * sizeof(bool)); memset(&m_ptrActionIndices, 0, ASW::Input::KEY_COUNT * sizeof(unsigned int *)); } ASW::Input:: ~Input() { unsigned int i; for (i=0; i= uchrKeys ) { // // All of the keys for the action are pressed, add it to the array as activated // p_ptrActions[uintActions].m_blnOn = true; p_ptrActions[uintActions].m_uintAction = m_clsActions[*ptrIndices].m_uintAction; uintActions++; } } while ( *(++ptrIndices) != ~0 ); } else { // // Check all actions that use this key // unsigned int * ptrIndices = m_ptrActionIndices[stuKeys[i].m_enmKey]; do { ptrKeys = m_clsActions[*ptrIndices].m_ptrKeys; uchrKeys = m_clsActions[*ptrIndices].m_uchrKeys; for (j=0; j= uchrKeys ) { // // This key is not pressed, add it to the array as inactive // p_ptrActions[uintActions].m_blnOn = false; p_ptrActions[uintActions].m_uintAction = m_clsActions[*ptrIndices].m_uintAction; uintActions++; } } while ( *(++ptrIndices) != ~0 ); m_blnKeys[stuKeys[i].m_enmKey] = false; } } p_uintAmount = uintActions; return blnResult; } const ASW::Input::KeyType * ASW::Input:: GetAction(const unsigned int p_uintIndex, unsigned int & p_uintAction, unsigned char & p_uchrAmount) const { ASW_ASSERT(p_uintIndex < m_clsActions.size(), "Index exceeds action list length"); p_uintAction = m_clsActions[p_uintIndex].m_uintAction; p_uchrAmount = m_clsActions[p_uintIndex].m_uchrKeys; return m_clsActions[p_uintIndex].m_ptrKeys; } /* An action and its associated key sequence are specified here. While this method can be called any time, it is usually called during initialization to set up default actions. It could also be called if the user changes key bindings. - If the key sequence is NULL, the action is removed (if it exists). - If the key sequence is already present, the current action is replaced with the new one, unless the action is ~0, in which case the key sequence and associated action are removed. - If the action is already present, the current key sequence for that action is replaced by the new one. Finally, if neither the action or key sequence are present, they are added to the action/sequence array. */ bool ASW::Input:: Set(const unsigned int p_uintAction, const ASW::Input::KeyType * p_ptrKeys, const unsigned char p_uchrAmount) { if ( p_ptrKeys == NULL ) { // // The KeyType array is NULL which means we remove the action with the corresponding identifier // for (unsigned int i=0; i= ptrTemp[j] ) { KeyType enmTemp = ptrTemp[i]; ptrTemp[i] = ptrTemp[j]; ptrTemp[j] = enmTemp; } } } // // Try to find the key sequence in the action array // for (i=0; i