Exemplo n.º 1
0
static void microengine(GKeyboard *k, uint8_t code, uint8_t flags) {
    if (flags)
        return;

    // Just send an event using the char
    k->c[0] = k->sc[0] = code;
    k->cntc = k->cntsc = 1;
    SendKeyboardEvent(k);
    k->cntc = k->cntsc = 0;
}
Exemplo n.º 2
0
//================================================================================
unsigned int ATHInputManager::Update()
{
	ReadKeyboard();

	m_fMouseDiffX = 0.0f;
	m_fMouseDiffY = 0.0f;

	if( ReadMouse() )
	{
		LONG lXMovement = m_diMouseState.lX;
		m_fMouseDiffX = lXMovement * m_fSensitivity;
		m_fMouseX += m_fMouseDiffX;

		LONG lYMovement = m_diMouseState.lY;
		m_fMouseDiffY = lYMovement * m_fSensitivity;
		m_fMouseY += m_fMouseDiffY;

		// Z is the scroll wheel, sensitivty doesnt change it
		LONG lZMovement = m_diMouseState.lZ;
		m_fMouseDiffZ = (float)lZMovement;

		if( m_fMouseX < 0 )
			m_fMouseX = 0;

		if (m_fMouseY < 0 )
			m_fMouseY = 0;

		if( m_fMouseX > (int)m_unScreenWidth )
			m_fMouseX = (float)m_unScreenWidth;

		if( m_fMouseY > (int)m_unScreenHeight )
			m_fMouseY = (float)m_unScreenHeight;

		//if (m_fMouseDiffY != 0.0f || m_fMouseDiffX != 0.0f)
			//std::cout << m_fMouseX << " " << m_fMouseY << '\n';
	}

	SendKeyboardEvent();
	SendMouseEvent();

	return 0;
}
Exemplo n.º 3
0
static void microengine(GKeyboard *k, uint8_t code, uint8_t flags) {
    const uint8_t	*pc;
    const uint8_t	*nrec;
    uint8_t			ver, diff, p1, p2;
#if MICROCODE_DEBUG
    unsigned	cnt;
#endif

    pc = k->pLayout;
    if (!pc) {
        if (flags)
            return;

        // Default is to just send an event using the char
        k->c[0] = k->sc[0] = code;
        k->cntc = k->cntsc = 1;
        SendKeyboardEvent(k);
        k->cntc = k->cntsc = 0;
        return;
    }

    // Check the layout header
    if (*pc++ != KMC_HEADERSTART || *pc++ != KMC_HEADER_ID1 || *pc++ != KMC_HEADER_ID2)
        return;

    // We only understand version 1 currently
    ver = *pc++;
    if (ver < KMC_HEADER_VER_MIN || ver > KMC_HEADER_VER_MAX)
        return;

    // Setup
    diff = code;
    if (k->cntsc >= sizeof(k->sc))
        flags |= FLAG_ERROR;
    else
        k->sc[k->cntsc++] = code;

#if MICROCODE_DEBUG
    cnt = 0;
#endif

    while(*pc++ == KMC_RECORDSTART) {
        // Get the record length
        p1 = *pc++;
        if (!p1) break;
        nrec = pc + p1;

#if MICROCODE_DEBUG
        cnt++;
#endif

        while(pc < nrec) {
            switch(*pc++) {
            case KMC_TEST_INIT:
                if (!(flags & FLAG_INIT))  goto nextrecord;
                break;
            case KMC_TEST_ERROR:
                if (!(flags & FLAG_ERROR)) goto nextrecord;
                break;
            case KMC_TEST_CODE:
                if (flags != 0) goto nextrecord;
                p1 = *pc++;
                if (p1 != code) goto nextrecord;
                diff = 0;
                break;
            case KMC_TEST_CODERANGE:
                if (flags != 0) goto nextrecord;
                p1 = *pc++;
                p2 = *pc++;
                if (code < p1 || code > p2) goto nextrecord;
                diff = code - p1;
                break;
            case KMC_TEST_CODETABLE:
                if (flags != 0) goto nextrecord;
                p1 = *pc++;
                for(p2 = 0; ; p2++, p1--, pc++) {
                    if (!p1) goto nextrecord;
                    if (*pc == code) break;
                }
                pc += p1;
                diff = p2;
                break;
            case KMC_TEST_STATEBIT:
                p1 = *pc++;
                if ((p1 & KMC_BIT_CLEAR)) {
                    if ((k->keystate & (1 << (p1 & 31)))) goto nextrecord;
                } else {
                    if (!(k->keystate & (1 << (p1 & 31)))) goto nextrecord;
                }
                break;
            case KMC_TEST_STATEOR:
                p1 = *pc++;
                if ((p1 & KMC_BIT_CLEAR)) {
                    if (!(k->keystate & (1 << (p1 & 31)))) break;
                } else {
                    if ((k->keystate & (1 << (p1 & 31)))) break;
                }
                p2 = *pc++;
                if ((p2 & KMC_BIT_CLEAR)) {
                    if (!(k->keystate & (1 << (p2 & 31)))) break;
                } else {
                    if ((k->keystate & (1 << (p2 & 31)))) break;
                }
                goto nextrecord;
            case KMC_TEST_STATEAND:
                p1 = *pc++;
                if ((p1 & KMC_BIT_CLEAR)) {
                    if ((k->keystate & (1 << (p1 & 31)))) goto nextrecord;
                } else {
                    if (!(k->keystate & (1 << (p1 & 31)))) goto nextrecord;
                }
                p2 = *pc++;
                if ((p2 & KMC_BIT_CLEAR)) {
                    if ((k->keystate & (1 << (p2 & 31)))) goto nextrecord;
                } else {
                    if (!(k->keystate & (1 << (p2 & 31)))) goto nextrecord;
                }
                break;
            case KMC_TEST_LAYOUTBIT:
                p1 = *pc++;
                if ((p1 & KMC_BIT_CLEAR)) {
                    if ((k->laystate & (1 << (p1 & 15)))) goto nextrecord;
                } else {
                    if (!(k->laystate & (1 << (p1 & 15)))) goto nextrecord;
                }
                break;
            case KMC_TEST_LAYOUTOR:
                p1 = *pc++;
                if ((p1 & KMC_BIT_CLEAR)) {
                    if (!(k->laystate & (1 << (p1 & 15)))) break;
                } else {
                    if ((k->laystate & (1 << (p1 & 15)))) break;
                }
                p2 = *pc++;
                if ((p2 & KMC_BIT_CLEAR)) {
                    if (!(k->laystate & (1 << (p2 & 15)))) break;
                } else {
                    if ((k->laystate & (1 << (p2 & 15)))) break;
                }
                goto nextrecord;
            case KMC_TEST_LAYOUTAND:
                p1 = *pc++;
                if ((p1 & KMC_BIT_CLEAR)) {
                    if ((k->laystate & (1 << (p1 & 15)))) goto nextrecord;
                } else {
                    if (!(k->laystate & (1 << (p1 & 15)))) goto nextrecord;
                }
                p2 = *pc++;
                if ((p2 & KMC_BIT_CLEAR)) {
                    if ((k->laystate & (1 << (p2 & 15)))) goto nextrecord;
                } else {
                    if (!(k->laystate & (1 << (p2 & 15)))) goto nextrecord;
                }
                break;
            case KMC_TEST_CODEBIT:
                if (flags != 0) goto nextrecord;
                p1 = *pc++;
                if ((p1 & KMC_BIT_CLEAR)) {
                    if ((code & (1 << (p1 & 7)))) goto nextrecord;
                } else {
                    if (!(code & (1 << (p1 & 7)))) goto nextrecord;
                }
                break;
            case KMC_TEST_CODEOR:
                if (flags != 0) goto nextrecord;
                p1 = *pc++;
                if ((p1 & KMC_BIT_CLEAR)) {
                    if (!(code & (1 << (p1 & 7)))) break;
                } else {
                    if ((code & (1 << (p1 & 7)))) break;
                }
                p2 = *pc++;
                if ((p2 & KMC_BIT_CLEAR)) {
                    if (!(code & (1 << (p2 & 7)))) break;
                } else {
                    if ((code & (1 << (p2 & 7)))) break;
                }
                goto nextrecord;
            case KMC_TEST_CODEAND:
                if (flags != 0) goto nextrecord;
                p1 = *pc++;
                if ((p1 & KMC_BIT_CLEAR)) {
                    if ((code & (1 << (p1 & 7)))) goto nextrecord;
                } else {
                    if (!(code & (1 << (p1 & 7)))) goto nextrecord;
                }
                p2 = *pc++;
                if ((p2 & KMC_BIT_CLEAR)) {
                    if ((code & (1 << (p2 & 7)))) goto nextrecord;
                } else {
                    if (!(code & (1 << (p2 & 7)))) goto nextrecord;
                }
                break;
            case KMC_TEST_LASTCODE:
                p1 = *pc++;
                if (k->cntsc < 2) goto nextrecord;
                if (p1 != k->sc[k->cntsc-2]) goto nextrecord;
                break;
            case KMC_TEST_SHIFT:
                if ((k->keystate & (GKEYSTATE_SHIFT_L|GKEYSTATE_SHIFT_R))) break;
                goto nextrecord;
            case KMC_TEST_NOSHIFT:
                if (!(k->keystate & (GKEYSTATE_SHIFT_L|GKEYSTATE_SHIFT_R))) break;
                goto nextrecord;
            case KMC_TEST_CTRL:
                if ((k->keystate & (GKEYSTATE_CTRL_L|GKEYSTATE_CTRL_R))) break;
                goto nextrecord;
            case KMC_TEST_NOCTRL:
                if (!(k->keystate & (GKEYSTATE_CTRL_L|GKEYSTATE_CTRL_R))) break;
                goto nextrecord;
            case KMC_TEST_ALT:
                if ((k->keystate & (GKEYSTATE_ALT_L|GKEYSTATE_ALT_R))) break;
                goto nextrecord;
            case KMC_TEST_NOALT:
                if (!(k->keystate & (GKEYSTATE_ALT_L|GKEYSTATE_ALT_R))) break;
                goto nextrecord;
            case KMC_TEST_CAPS:
                if ((k->keystate & GKEYSTATE_CAPSLOCK)) {
                    if (!(k->keystate & (GKEYSTATE_SHIFT_L|GKEYSTATE_SHIFT_R))) break;
                } else {
                    if ((k->keystate & (GKEYSTATE_SHIFT_L|GKEYSTATE_SHIFT_R))) break;
                }
                goto nextrecord;
            case KMC_TEST_NOCAPS:
                if ((k->keystate & GKEYSTATE_CAPSLOCK)) {
                    if ((k->keystate & (GKEYSTATE_SHIFT_L|GKEYSTATE_SHIFT_R))) break;
                } else {
                    if (!(k->keystate & (GKEYSTATE_SHIFT_L|GKEYSTATE_SHIFT_R))) break;
                }
                goto nextrecord;
            case KMC_TEST_NUMLOCK:
                if ((k->keystate & GKEYSTATE_NUMLOCK)) break;
                goto nextrecord;
            case KMC_TEST_NONUMLOCK:
                if (!(k->keystate & GKEYSTATE_NUMLOCK)) break;
                goto nextrecord;

            case KMC_ACT_STOP:
#if MICROCODE_DEBUG
                fprintf(stderr, "Executed STOP:  Records=%2u Flags=0x%02X Code=0x%02X\n", cnt, flags, code);
                fflush(stderr);
#endif
                return;
            case KMC_ACT_DONE:
                SendKeyboardEvent(k);
                k->cntc = k->cntsc = 0;
                k->keystate &= ~(GKEYSTATE_KEYUP|GKEYSTATE_SPECIAL);
#if MICROCODE_DEBUG
                fprintf(stderr, "Executed DONE:  Records=%2u Flags=0x%02X Code=0x%02X\n", cnt, flags, code);
                fflush(stderr);
#endif
                return;
            case KMC_ACT_RESET:
                k->cntc = k->cntsc = 0;
                k->keystate &= ~(GKEYSTATE_KEYUP|GKEYSTATE_SPECIAL);
                break;
            case KMC_ACT_STATEBIT:
                p1 = *pc++;
                if ((p1 & KMC_BIT_INVERT))
                    k->keystate ^= (1 << (p1 & 31));
                else if ((p1 & KMC_BIT_CLEAR))
                    k->keystate &= ~(1 << (p1 & 31));
                else
                    k->keystate |= (1 << (p1 & 31));
                break;
            case KMC_ACT_LAYOUTBIT:
                p1 = *pc++;
                if ((p1 & KMC_BIT_INVERT))
                    k->laystate ^= (1 << (p1 & 15));
                else if ((p1 & KMC_BIT_CLEAR))
                    k->laystate &= ~(1 << (p1 & 15));
                else
                    k->laystate |= (1 << (p1 & 15));
                break;
            case KMC_ACT_CODEBIT:
                p1 = *pc++;
                if ((p1 & KMC_BIT_INVERT))
                    code ^= (1 << (p1 & 7));
                else if ((p1 & KMC_BIT_CLEAR))
                    code &= ~(1 << (p1 & 7));
                else
                    code |= (1 << (p1 & 7));
                break;
            case KMC_ACT_CHAR:
                if (k->cntc >= sizeof(k->c)) goto codeerror;
                k->c[k->cntc++] = *pc++;
                break;
            case KMC_ACT_CHARCODE:
                if (k->cntc >= sizeof(k->c)) goto codeerror;
                k->c[k->cntc++] = code;
                break;
            case KMC_ACT_CHARRANGE:
                if (k->cntc >= sizeof(k->c)) goto codeerror;
                k->c[k->cntc++] = diff + *pc++;
                break;
            case KMC_ACT_CHARTABLE:
                p1 = *pc++;
                if (diff < p1) {
                    if (k->cntc >= sizeof(k->c)) goto codeerror;
                    k->c[k->cntc++] = pc[diff];
                }
                pc += p1;
                break;
            case KMC_ACT_CLEAR:
                k->cntc = 0;
                break;
            case KMC_ACT_CHARADD:
                p1 = *pc++;
                if (!k->cntc)
                    k->c[k->cntc++] = 0;
                k->c[k->cntc-1] = k->c[k->cntc-1] * p1 + diff;
                break;
            case KMC_ACT_DATA:
                p1 = *pc++;
                if (gkvmt(k)->putdata)
                    gkvmt(k)->putdata(k, p1);
                break;

            default:
codeerror:
#if MICROCODE_DEBUG
                fprintf(stderr, "Executed ERROR: Records=%2u Flags=0x%02X Code=0x%02X\n", cnt, flags, code);
                cnt = 0;
                fflush(stderr);
#endif

                // Prevent recursion
                if (flags & FLAG_ERROR)
                    return;

                // Process as an error
                flags |= FLAG_ERROR;
                nrec = k->pLayout + 4;			// Jump back to the end of the header to process the error
                goto nextrecord;				// Nothing left to do here.
            }
        }

nextrecord:
        pc = nrec;
    }

#if MICROCODE_DEBUG
    fprintf(stderr, "Executed END:   Records=%2u Flags=0x%02X Code=0x%02X\n", cnt, flags, code);
    fflush(stderr);
#endif
}