Project

General

Profile

SO3Engine
KeyboardHook.cpp
Go to the documentation of this file.
1/*
2 This file is part of Hikari, a library that allows developers
3 to use Flash in their Ogre3D applications.
4
5 Copyright (C) 2008 Adam J. Simmons
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21/*********************************************************************************************
22 ___ ___ .__ __ .__
23 / | \|__| | _______ _______|__|
24 / ~ \ | |/ /\__ \\_ __ \ |
25 \ Y / | < / __ \| | \/ |
26 \___|_ /|__|__|_ \‍(____ /__| |__| v0.4
27 \/ \/ \/
28
29
30 * Zed Games PC Development Team - Jaime Crespillo Vilchez (jcrespillo@zed.com)
31 * Build: 0.1 - Date: 13/10/2008
32 * Undocked version of Hikari Lib
33 * Brief: Added WM_COPY, WM_PASTE, WM_CUT + fixed lost focus input bug
34 **********************************************************************************************/
37
38using namespace Hikari;
39using namespace Hikari::Impl;
40
41LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam);
42
44
46{
47 instance = this;
48
49 HINSTANCE hInstance = GetModuleHandle(0);
50
51 getMsgHook = SetWindowsHookEx(WH_GETMESSAGE, GetMessageProc, hInstance, GetCurrentThreadId());
52}
53
55{
56 UnhookWindowsHookEx(getMsgHook);
57
58 instance = 0;
59}
60
61void KeyboardHook::handleHook(UINT msg, HWND hwnd, WPARAM wParam, LPARAM lParam)
62{
63 switch (msg)
64 {
65
66 case WM_ACTIVATE:
67 {
69 bool active = (LOWORD(wParam) != WA_INACTIVE);
70 if (!active)
71 break;
72 }
73 case WM_KEYDOWN:
74 case WM_KEYUP:
75 case WM_CHAR:
76 case WM_COPY:
77 case WM_PASTE:
78 case WM_CUT:
79 case WM_DEADCHAR:
80 case WM_SYSKEYDOWN:
81 case WM_SYSKEYUP:
82 case WM_SYSDEADCHAR:
83 case WM_SYSCHAR:
84 case WM_IME_CHAR:
85 case WM_IME_COMPOSITION:
86 case WM_IME_COMPOSITIONFULL:
87 case WM_IME_CONTROL:
88 case WM_IME_ENDCOMPOSITION:
89 case WM_IME_KEYDOWN:
90 case WM_IME_KEYUP:
91 case WM_IME_NOTIFY:
92 case WM_IME_REQUEST:
93 case WM_IME_SELECT:
94 case WM_IME_SETCONTEXT:
95 case WM_IME_STARTCOMPOSITION:
96 case WM_HELP:
97 case WM_CANCELMODE:
98 {
100 if (manager)
101 manager->injectKeyEvent(msg, wParam, lParam);
102 break;
103 }
104 }
105}
106
107
108LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam)
109{
110 if (nCode == HC_ACTION)
111 {
112 MSG *msg = (MSG*)lParam;
113 if (wParam & PM_REMOVE)
114 KeyboardHook::instance->handleHook(msg->message, msg->hwnd, msg->wParam, msg->lParam);
115 }
116
117 return CallNextHookEx(KeyboardHook::instance->getMsgHook, nCode, wParam, lParam);
118}
LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam)
unsigned int UINT
Definition SO3Android.h:58
struct HINSTANCE__ * hInstance
static HikariManager * getSingletonPtr()
Definition Hikari.cpp:126
void injectKeyEvent(UINT msg, WPARAM wParam, LPARAM lParam)
Definition Hikari.cpp:388
static KeyboardHook * instance
void handleHook(UINT msg, HWND hwnd, WPARAM wParam, LPARAM lParam)