Ejemplo n.º 1
0
static int CmpCompare(void* arg, const char* a, size_t alen, const char* b, size_t blen) {
	u_int64_t av = convertToKey(a, alen);
	u_int64_t bv = convertToKey(b, alen);
	if (av < bv) return -1;
	else if (av > bv) return +1;
	return 0;
}
Ejemplo n.º 2
0
   void  HGEInput::pollKeyInput(hgeInputEvent &ki)
   {
       if (ki.type != INPUT_KEYDOWN 
           && ki.type != INPUT_KEYUP )
       {
            return ;
       }
       
       if (ki.type == INPUT_KEYDOWN)
       {
           Key keyObj = convertToKey(ki.key, ki.chr);
 
           KeyInput keyInput(keyObj, KeyInput::Pressed);
 
           keyInput.setNumericPad(isNumericPad(ki.key));
 
           keyInput.setShiftPressed(ki.flags & HGEINP_SHIFT);
           keyInput.setAltPressed(ki.flags & HGEINP_ALT);
           keyInput.setControlPressed(ki.flags & HGEINP_CTRL);
       
           mKeyInputQueue.push(keyInput);
       }
 
       if (ki.type == INPUT_KEYUP)
       {
           Key keyObj = convertToKey(ki.key, ki.chr);
 
           KeyInput keyInput(keyObj, KeyInput::Released);
 
           keyInput.setNumericPad(isNumericPad(ki.key));
 
           keyInput.setShiftPressed(ki.flags & HGEINP_SHIFT);
           keyInput.setAltPressed(ki.flags & HGEINP_ALT);
           keyInput.setControlPressed(ki.flags & HGEINP_CTRL);
       
           mKeyInputQueue.push(keyInput);
       }
   }
Ejemplo n.º 3
0
    void OpenLayerInput::pollKeyInput()
    {
        int unicode, scancode;

        if (keyboard_needs_poll())
        {
            poll_keyboard();
        }

        while (keypressed())
        {
            unicode = ureadkey(&scancode);
            Key keyObj = convertToKey(scancode, unicode);

            KeyInput keyInput(keyObj, KeyInput::Pressed);

            keyInput.setNumericPad(isNumericPad(scancode));
            keyInput.setShiftPressed(key_shifts & KB_SHIFT_FLAG);
            keyInput.setAltPressed(key_shifts & KB_ALT_FLAG);
            keyInput.setControlPressed(key_shifts & KB_CTRL_FLAG);
#ifdef KB_COMMAND_FLAG
            keyInput.setMetaPressed(key_shifts & (KB_COMMAND_FLAG |
                                                  KB_LWIN_FLAG |
                                                  KB_RWIN_FLAG));
#else
            keyInput.setMetaPressed(key_shifts & (KB_LWIN_FLAG |
                                                  KB_RWIN_FLAG));
#endif


            mKeyQueue.push(keyInput);

            mPressedKeys[scancode] = keyInput;
        }

        if (key[KEY_ALT] && mPressedKeys.find(KEY_ALT) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_ALT, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_ALT] = keyInput;
        }

        if (key[KEY_ALTGR] && mPressedKeys.find(KEY_ALTGR) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_ALTGR, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_ALTGR] = keyInput;
        }

        if (key[KEY_LSHIFT] && mPressedKeys.find(KEY_LSHIFT) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_LSHIFT, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_LSHIFT] = keyInput;
        }
    
        if (key[KEY_RSHIFT] && mPressedKeys.find(KEY_RSHIFT) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_RSHIFT, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_RSHIFT] = keyInput;
        }
		
        if (key[KEY_LCONTROL] && mPressedKeys.find(KEY_LCONTROL) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_LCONTROL, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_LCONTROL] = keyInput;
        }

        if (key[KEY_RCONTROL] && mPressedKeys.find(KEY_RCONTROL) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_RCONTROL, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_RCONTROL] = keyInput;
        }

        // Check for released keys
        std::map<int, KeyInput>::iterator iter, tempIter;
        for (iter = mPressedKeys.begin(); iter != mPressedKeys.end(); )
        {
            if (!key[iter->first])
            {
                KeyInput keyInput(iter->second.getKey(), KeyInput::Released);
                keyInput.setNumericPad(iter->second.isNumericPad());
                keyInput.setShiftPressed(iter->second.isShiftPressed());
                keyInput.setAltPressed(iter->second.isAltPressed());
                keyInput.setControlPressed(iter->second.isControlPressed());

                mKeyQueue.push(keyInput);

                tempIter = iter;
                iter++;
                mPressedKeys.erase(tempIter);
            }
            else
            {
                iter++;
            }
        }
    }