2
Free Pascal port of the OpenPTC C++ library.
3
Copyright (C) 2001-2003 Nikolay Nikolov (nickysn@users.sourceforge.net)
4
Original C++ version by Glenn Fiedler (ptc@gaffer.org)
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
Constructor TWin32Keyboard.Create(window : HWND; thread : DWord; multithreaded : Boolean);
26
Inherited Create(window, thread);
27
m_monitor := TWin32Monitor.Create;
28
m_event := TWin32Event.Create;
44
m_multithreaded := multithreaded;
47
Destructor TWin32Keyboard.Destroy;
55
Function TWin32Keyboard.internal_PeekKey(window : TWin32Window; k : TPTCKey) : Boolean;
58
{ check enabled flag }
65
{ enter monitor if multithreaded }
66
If m_multithreaded Then
76
k.ASSign(m_buffer[m_tail]);
78
{ leave monitor if multithreaded }
79
If m_multithreaded Then
83
Procedure TWin32Keyboard.internal_ReadKey(window : TWin32Window; k : TPTCKey);
92
{ check enabled flag }
95
read := TPTCKey.Create;
99
{ check if multithreaded }
100
If m_multithreaded Then
105
{ wait for key event }
123
{ update until ready }
132
If Assigned(read) Then
138
Procedure TWin32Keyboard.enable;
145
Procedure TWin32Keyboard.disable;
148
{ disable buffering }
152
Function TWin32Keyboard.WndProc(hWnd : HWND; message : DWord; wParam : WPARAM; lParam : LPARAM) : LRESULT;
157
KeyStateArray : Array[0..255] Of Byte;
165
{ check enabled flag }
166
If Not m_enabled Then
169
{ process key message }
170
If (message = WM_KEYDOWN) Or (message = WM_KEYUP) {Or ((message = WM_SYSKEYDOWN) And ((lParam And (1 Shl 29)) <> 0))} Then
172
If message = WM_KEYUP Then
178
If wParam = VK_MENU Then
182
If wParam = VK_SHIFT Then
186
If wParam = VK_CONTROL Then
190
{ enter monitor if multithreaded }
191
If m_multithreaded Then
196
If GetKeyboardState(@KeyStateArray) Then
198
scancode := (lParam Shr 16) And $FF;
199
{todo: ToUnicode (Windows NT)}
200
tmp := ToAscii(wParam, scancode, @KeyStateArray, @AsciiBuf, 0);
201
If (tmp = 1) Or (tmp = 2) Then
205
// Writeln('[', AsciiBuf, ']'); {???? todo: dead keys ????}
209
// Write(Chr(AsciiBuf));
210
{todo: codepage -> unicode}
211
If AsciiBuf <= 126 Then
218
{ handle key repeat count }
219
For i := 1 To lParam And $FFFF Do
220
{ create and insert key object }
221
insert(TPTCKey.Create(wParam, uni, m_alt, m_shift, m_control, press));
223
{ check multithreaded flag }
224
If m_multithreaded Then
234
If message = WM_KEYUP Then
236
If wParam = VK_MENU Then
240
If wParam = VK_SHIFT Then
244
If wParam = VK_CONTROL Then
246
m_control := False;*)
249
Procedure TWin32Keyboard.insert(_key : TPTCKey);
252
{ check for overflow }
253
If (m_head <> (m_tail - 1)) And
254
((m_tail <> 0) Or (m_head <> High(m_buffer))) Then
256
{ insert key at head }
257
m_buffer[m_head] := _key;
262
{ wrap head from end to start }
263
If m_head > High(m_buffer) Then
264
m_head := Low(m_buffer);
268
Function TWin32Keyboard.remove : TPTCKey;
271
{ return key data from tail }
272
remove := m_buffer[m_tail];
277
{ wrap tail from end to start }
278
If m_tail > High(m_buffer) Then
279
m_tail := Low(m_buffer);
282
Function TWin32Keyboard.ready : Boolean;
285
ready := m_head <> m_tail;