/** * @file XTPKeyboardManager.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPKEYBOARDMANAGER_H__) # define __XTPKEYBOARDMANAGER_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** * @brief * CXTPKeyboardManager class used to handle keyboard hooks. */ class _XTP_EXT_CLASS CXTPKeyboardManager : public CNoTrackObject { public: /** * @brief * Constructs a CXTPKeyboardManager object. */ CXTPKeyboardManager(); /** * @brief * Destroys a CXTPKeyboardManager object, handles cleanup and deallocation. */ ~CXTPKeyboardManager(); public: /** * @brief * This method is called to start/end keyboard hooks. * @param bSetup TRUE to start keyboard hooks, FALSE to end keyboard hooks. * @see * SetupCallWndProcHook */ void SetupKeyboardHook(BOOL bSetup = TRUE); /** * @brief * This method is called to start/end message hooks. * @param bSetup TRUE to start message hooks, FALSE to end message hooks. * @see * SetupKeyboardHook */ void SetupCallWndProcHook(BOOL bSetup = TRUE); /** * @brief * Call this method to hook keyboard notifications. * @param pHook CXTPHookManagerHookAble object that will receive keyboard notifications. * @see * UnhookKeyboard */ void HookKeyboard(CXTPHookManagerHookAble* pHook); /** * @brief * Call this method to unhook keyboard notifications. * @param pHook CXTPHookManagerHookAble object to remove. * @see * HookKeyboard */ void UnhookKeyboard(CXTPHookManagerHookAble* pHook); /** * @brief * Determines if the keyboard is hooked. * @return * TRUE if the keyboard is hooked, otherwise FALSE. */ BOOL IsKeyboardHooked() const; /** * @brief * This method is called to process keyboard hooks. * @param nMessage Message to process. * @param wParam Message specified parameter. * @param lParam Message specified parameter. * @return * TRUE if the message was processed, otherwise FALSE. */ BOOL ProcessKeyboardHooks(UINT nMessage, WPARAM wParam, LPARAM lParam = 0); /** * @brief * Increments/decrements input lock counter. If there is at least * one input lock enabled then tracking won't be reported in any event. * @see * IsInputLocked */ void LockInput(); /** * @brief * Increments/decrements input lock counter. If there is at least * one input lock enabled then tracking won't be reported in any event. * @see * IsInputLocked */ void UnlockInput(); /** * @brief * Determines if there is at least one input lock. * @return * TRUE if there is at least one input lock enabled. * @see * LockInput, UnlockInput */ BOOL IsInputLocked() const; protected: /** @cond */ static LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK CallWndProc(int code, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK GetMessageProc(int code, WPARAM wParam, LPARAM lParam); # ifdef _XTP_COMMANDBARS_ACTIVEX public: void SetupGetMessageHook(BOOL bSetup = TRUE); # endif /** @endcond */ protected: HHOOK m_hHookKeyboard; /**< Keyboard hook. */ HHOOK m_hHookCallWndProc; /**< Message hook. */ HHOOK m_hHookGetMessage; /**< Message hook. */ LONG m_nInputLockCount; /**< Number of input locks. */ # ifdef _AFXDLL AFX_MODULE_STATE* m_pModuleState; /**< Module state. */ # endif static CThreadLocal _xtpKeyboardThreadState; /**< Instance of Keyboard hook. */ CList m_lstKeyboardHooks; /**< List of keyboard hooks. */ private: friend CXTPKeyboardManager* XTPKeyboardManager(); friend class CXTPCommandBars; }; AFX_INLINE BOOL CXTPKeyboardManager::IsKeyboardHooked() const { return m_lstKeyboardHooks.GetCount() > 0; } AFX_INLINE BOOL CXTPKeyboardManager::IsInputLocked() const { return 0 < m_nInputLockCount; } AFX_INLINE CXTPKeyboardManager* XTPKeyboardManager() { return CXTPKeyboardManager::_xtpKeyboardThreadState.GetData(); } /** @cond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif //#if !defined(__XTPKEYBOARDMANAGER_H__) /** @endcond */