Formatting

This commit is contained in:
Klaus Basan
2018-02-24 13:01:37 +01:00
parent 2db1e0b258
commit 80c9030bdd
4 changed files with 24 additions and 37 deletions

View File

@@ -24,8 +24,7 @@ namespace BlackInput
IJoystick::IJoystick(QObject *parent) : IJoystick::IJoystick(QObject *parent) :
QObject(parent) QObject(parent)
{ { }
}
std::unique_ptr<IJoystick> IJoystick::create(QObject *parent) std::unique_ptr<IJoystick> IJoystick::create(QObject *parent)
{ {

View File

@@ -33,7 +33,7 @@ namespace BlackInput
this->initDirectInput(); this->initDirectInput();
this->enumJoystickDevices(); this->enumJoystickDevices();
this->filterJoystickDevices(); this->filterJoystickDevices();
if (!m_availableJoystickDevices.isEmpty()) { createJoystickDevice(); } if (!m_availableJoystickDevices.isEmpty()) { this->createJoystickDevice(); }
} }
CJoystickWindows::~CJoystickWindows() CJoystickWindows::~CJoystickWindows()
@@ -167,7 +167,7 @@ namespace BlackInput
return hr; return hr;
} }
createHelperWindow(); this->createHelperWindow();
// Set cooperative level // Set cooperative level
if (FAILED(hr = m_directInputDevice->SetCooperativeLevel(m_helperWindow, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))) if (FAILED(hr = m_directInputDevice->SetCooperativeLevel(m_helperWindow, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)))
@@ -201,7 +201,7 @@ namespace BlackInput
CLogMessage(this).info("Created joystick device '%1' with %2 buttons") << deviceData.deviceName << deviceCaps.dwButtons; CLogMessage(this).info("Created joystick device '%1' with %2 buttons") << deviceData.deviceName << deviceCaps.dwButtons;
startTimer(50); this->startTimer(50);
return hr; return hr;
} }
@@ -210,13 +210,13 @@ namespace BlackInput
HINSTANCE hInstance = GetModuleHandle(nullptr); HINSTANCE hInstance = GetModuleHandle(nullptr);
WNDCLASS wce; WNDCLASS wce;
/* Make sure window isn't created twice. */ // Make sure window isn't created twice
if (m_helperWindow != nullptr) if (m_helperWindow != nullptr)
{ {
return 0; return 0;
} }
/* Create the class. */ // Create the class
ZeroMemory(&wce, sizeof(WNDCLASS)); ZeroMemory(&wce, sizeof(WNDCLASS));
wce.lpfnWndProc = DefWindowProc; wce.lpfnWndProc = DefWindowProc;
wce.lpszClassName = (LPCWSTR) m_helperWindowClassName; wce.lpszClassName = (LPCWSTR) m_helperWindowClassName;
@@ -317,7 +317,7 @@ namespace BlackInput
for (CJoystickDeviceInput input : m_joystickDeviceInputs) for (CJoystickDeviceInput input : m_joystickDeviceInputs)
{ {
qint32 buttonIndex = input.m_offset - DIJOFS_BUTTON0; const qint32 buttonIndex = input.m_offset - DIJOFS_BUTTON0;
updateAndSendButtonStatus(buttonIndex, state.rgbButtons[buttonIndex] & 0x80); updateAndSendButtonStatus(buttonIndex, state.rgbButtons[buttonIndex] & 0x80);
} }

View File

@@ -13,7 +13,6 @@ using namespace BlackMisc::Input;
namespace BlackInput namespace BlackInput
{ {
static const auto &keyMapping() static const auto &keyMapping()
{ {
static const QHash<int, KeyCode> hash static const QHash<int, KeyCode> hash
@@ -69,13 +68,11 @@ namespace BlackInput
CKeyboardWindows::CKeyboardWindows(QObject *parent) : CKeyboardWindows::CKeyboardWindows(QObject *parent) :
IKeyboard(parent), IKeyboard(parent),
m_keyboardHook(nullptr) m_keyboardHook(nullptr)
{ { }
}
CKeyboardWindows::~CKeyboardWindows() CKeyboardWindows::~CKeyboardWindows()
{ {
if (m_keyboardHook) if (m_keyboardHook) { UnhookWindowsHookEx(m_keyboardHook); }
UnhookWindowsHookEx(m_keyboardHook);
} }
bool CKeyboardWindows::init() bool CKeyboardWindows::init()
@@ -95,7 +92,7 @@ namespace BlackInput
if (key == Key_Unknown) { return; } if (key == Key_Unknown) { return; }
m_keyCombination.addKeyboardKey(CKeyboardKey(key)); m_keyCombination.addKeyboardKey(CKeyboardKey(key));
} }
else if ((event == WM_KEYUP) || (event == WM_SYSKEYUP) ) else if ((event == WM_KEYUP) || (event == WM_SYSKEYUP))
{ {
auto key = keyMapping().value(vkcode); auto key = keyMapping().value(vkcode);
if (key == Key_Unknown) { return; } if (key == Key_Unknown) { return; }
@@ -112,7 +109,7 @@ namespace BlackInput
{ {
if (nCode == HC_ACTION) if (nCode == HC_ACTION)
{ {
KBDLLHOOKSTRUCT *keyboardEvent =reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam); KBDLLHOOKSTRUCT *keyboardEvent = reinterpret_cast<KBDLLHOOKSTRUCT *>(lParam);
WPARAM vkCode = keyboardEvent->vkCode; WPARAM vkCode = keyboardEvent->vkCode;
g_keyboardWindows->processKeyEvent(vkCode, wParam); g_keyboardWindows->processKeyEvent(vkCode, wParam);
} }

View File

@@ -26,55 +26,46 @@
namespace BlackInput namespace BlackInput
{ {
//! \brief Windows implemenation of IKeyboard using hook procedure //! Windows implemenation of IKeyboard using hook procedure
class BLACKINPUT_EXPORT CKeyboardWindows : public IKeyboard class BLACKINPUT_EXPORT CKeyboardWindows : public IKeyboard
{ {
Q_OBJECT Q_OBJECT
public: public:
//! Copy Constructor
CKeyboardWindows(CKeyboardWindows const &) = delete;
//! \brief Copy Constructor //! Assignment operator
CKeyboardWindows(CKeyboardWindows const&) = delete; CKeyboardWindows &operator=(CKeyboardWindows const &) = delete;
//! \brief Assignment operator //! Destructor
CKeyboardWindows &operator=(CKeyboardWindows const&) = delete;
//! \brief Destructor
virtual ~CKeyboardWindows(); virtual ~CKeyboardWindows();
//! \brief Keyboard hook handle //! Keyboard hook handle
HHOOK keyboardHook() const { return m_keyboardHook; } HHOOK keyboardHook() const { return m_keyboardHook; }
//! \private //! \private
void processKeyEvent(WPARAM vkCode, uint event); void processKeyEvent(WPARAM vkCode, uint event);
protected: protected:
//! \copydoc IKeyboard::init() //! \copydoc IKeyboard::init()
virtual bool init() override; virtual bool init() override;
private: private:
friend class IKeyboard; friend class IKeyboard;
//! \brief Constructor //! Constructor
CKeyboardWindows(QObject *parent = nullptr); CKeyboardWindows(QObject *parent = nullptr);
void addKey(WPARAM vkcode); void addKey(WPARAM vkcode);
void removeKey(WPARAM vkcode); void removeKey(WPARAM vkcode);
/*! //! Keyboard hook procedure
* \brief Keyboard hook procedure
* \param nCode
* \param wParam
* \param lParam
* \return
*/
static LRESULT CALLBACK keyboardProc(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK keyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
BlackMisc::Input::CHotkeyCombination m_keyCombination; //!< Set of virtual keys pressed in the last cycle
BlackMisc::Input::CHotkeyCombination m_keyCombination; //!< Set of virtual keys pressed in the last cycle HHOOK m_keyboardHook; //!< Keyboard hook handle
HHOOK m_keyboardHook; //!< Keyboard hook handle
}; };
} }
#endif // BLACKINPUT_KEYBOARD_WINDOWS_H #endif // guard