Пример #1
0
void
CKeyState::updateKeyState()
{
	// reset our state
	memset(&m_keys, 0, sizeof(m_keys));
	memset(&m_syntheticKeys, 0, sizeof(m_syntheticKeys));
	memset(&m_keyClientData, 0, sizeof(m_keyClientData));
	memset(&m_serverKeys, 0, sizeof(m_serverKeys));
	m_activeModifiers.clear();

	// get the current keyboard state
	KeyButtonSet keysDown;
	pollPressedKeys(keysDown);
	for (KeyButtonSet::const_iterator i = keysDown.begin();
								i != keysDown.end(); ++i) {
		m_keys[*i] = 1;
	}

	// get the current modifier state
	m_mask = pollActiveModifiers();

	// set active modifiers
	CAddActiveModifierContext addModifierContext(pollActiveGroup(), m_mask,
												m_activeModifiers);
	m_keyMap.foreachKey(&CKeyState::addActiveModifierCB, &addModifierContext);

	LOG((CLOG_DEBUG1 "modifiers on update: 0x%04x", m_mask));
}
Пример #2
0
void
XWindowsKeyState::pollPressedKeys(KeyButtonSet& pressedKeys) const
{
	char keys[32];
	XQueryKeymap(m_display, keys);
	for (UInt32 i = 0; i < 32; ++i) {
		for (UInt32 j = 0; j < 8; ++j) {
			if ((keys[i] & (1u << j)) != 0) {
				pressedKeys.insert(8 * i + j);
			}
		}
	}
}
void
CMSWindowsKeyState::pollPressedKeys(KeyButtonSet& pressedKeys) const
{
	BYTE keyState[256];
	if (!GetKeyboardState(keyState)) {
		LOG((CLOG_ERR "GetKeyboardState returned false on pollPressedKeys"));
		return;
	}
	for (KeyButton i = 1; i < 256; ++i) {
		if ((keyState[i] & 0x80) != 0) {
			pressedKeys.insert(i);
		}
	}
}
Пример #4
0
void
OSXKeyState::pollPressedKeys(KeyButtonSet& pressedKeys) const
{
	::KeyMap km;
	GetKeys(km);
	const UInt8* m = reinterpret_cast<const UInt8*>(km);
	for (UInt32 i = 0; i < 16; ++i) {
		for (UInt32 j = 0; j < 8; ++j) {
			if ((m[i] & (1u << j)) != 0) {
				pressedKeys.insert(mapVirtualKeyToKeyButton(8 * i + j));
			}
		}
	}
}