vdfsplat / AppSrc / cVirtualKeys.pkg
History | View | Annotate | Download (12.7 KB)
1 |
//TH-Header |
---|---|
2 |
//***************************************************************************************** |
3 |
// Copyright (c) 2004 Debug Project |
4 |
// All rights reserved. |
5 |
// |
6 |
// $FileName : cVirtualKeys package |
7 |
// $ProjectName : DebugAssistent |
8 |
// $Authors : Wil van Antwerpen |
9 |
// $Created : 27.07.2004 09:51 |
10 |
// $Type : (C)opyright 2004 Antwise Solutions |
11 |
// |
12 |
// Contents: A virtual keyboard that can be used to send keycharacters |
13 |
// to the windows object that currently has the focus. |
14 |
// This includes all characters defined in the dataflex characterset. |
15 |
// |
16 |
// Ex. |
17 |
// Procedure OnSetFocus |
18 |
// Send Key Of ghoVirtualKeyboard (Key_Ctrl+Key_End) |
19 |
// End_Procedure // OnSetFocus |
20 |
// |
21 |
// This overrides the default behaviour of a form to show it's |
22 |
// value selected into nonselected. |
23 |
// |
24 |
//***************************************************************************************** |
25 |
//TH-RevisionStart |
26 |
//TH-RevisionEnd |
27 |
|
28 |
|
29 |
Use cVirtualKeys.h // |
30 |
// |
31 |
// |
32 |
// Note: Some of the functionality of this package may also |
33 |
// have been declared as commands in the winbase.pkg file. |
34 |
// The problem with those commands is however that they are |
35 |
// undocumented and can change at any revision of VDF |
36 |
// |
37 |
// |
38 |
|
39 |
|
40 |
Integer ghoVirtualKeyboard |
41 |
|
42 |
Class cKeyList Is a List |
43 |
|
44 |
//Insert your Properties here. |
45 |
Procedure Construct_Object |
46 |
Forward Send Construct_Object |
47 |
Set Focus_Mode To nonfocusable |
48 |
Set Visible_State To False |
49 |
Set Skip_State To True |
50 |
End_Procedure // Construct_Object |
51 |
|
52 |
Function Find_DFKey String ElemStr Returns Integer |
53 |
Integer ndx retVal ArrMax |
54 |
String ArrVal |
55 |
Get item_count To ArrMax |
56 |
Move -1 To retVal |
57 |
Move 0 To ndx |
58 |
While (ndx < ArrMax And retVal = -1) |
59 |
Get message Item ndx To ArrVal |
60 |
If ArrVal Eq ElemStr Move ndx To retVal |
61 |
Calc (ndx + 1) To ndx |
62 |
End |
63 |
If (retVal <> -1) Begin |
64 |
Get Value Item retVal To retval |
65 |
End |
66 |
Function_Return retVal |
67 |
End_Function // Find_DFKey |
68 |
|
69 |
Function Find_VK String ElemStr Returns Integer |
70 |
Integer ndx retVal ArrMax |
71 |
String ArrVal |
72 |
Get item_count To ArrMax |
73 |
Move -1 To retVal |
74 |
Move 0 To ndx |
75 |
While (ndx < ArrMax And retVal = -1) |
76 |
Get array_value Item ndx To ArrVal |
77 |
If ArrVal Eq ElemStr Move ndx To retVal |
78 |
Calc (ndx + 1) To ndx |
79 |
End |
80 |
If (retVal <> -1) Begin |
81 |
Get message Item retVal To retval |
82 |
End |
83 |
Function_Return retVal |
84 |
End_Function // Find_VK |
85 |
|
86 |
// Maps a DF key character (KEY_...) to it's Virtual Key |
87 |
// counterpart |
88 |
Function MapDFToVirtual Integer iKey Returns Integer |
89 |
Integer iVK |
90 |
If ( ((iKey>=65) And (iKey<=90)) Or ((iKey>=48) And (iKey<=57))) Begin |
91 |
// A .. Z == 65 .. 90 |
92 |
// 0..9 == 48 .. 57 |
93 |
Move iKey To iVK |
94 |
End |
95 |
Else Begin |
96 |
Get Find_VK iKey To iVK |
97 |
End |
98 |
Function_Return iVK |
99 |
End_Function // MapDFToVirtual |
100 |
|
101 |
Function MapVirtualToDF Integer iVK Returns Integer |
102 |
End_Function // MapVirtualToDF |
103 |
|
104 |
Procedure FillKeyArray |
105 |
// message // value |
106 |
Send Add_Item KEY_ENTER VK_RETURN |
107 |
Send Add_Item KEY_TAB VK_TAB |
108 |
Send Add_Item KEY_BACK_SPACE VK_BACK |
109 |
Send Add_Item KEY_ESCAPE VK_ESCAPE |
110 |
Send Add_Item KEY_UP_ARROW VK_UP |
111 |
Send Add_Item KEY_DOWN_ARROW VK_DOWN |
112 |
Send Add_Item KEY_LEFT_ARROW VK_LEFT |
113 |
Send Add_Item KEY_RIGHT_ARROW VK_RIGHT |
114 |
Send Add_Item KEY_HOME VK_HOME |
115 |
Send Add_Item KEY_END VK_END |
116 |
Send Add_Item KEY_PGUP VK_PRIOR |
117 |
Send Add_Item KEY_PGDN VK_NEXT |
118 |
Send Add_Item KEY_INSERT VK_INSERT |
119 |
Send Add_Item KEY_DELETE VK_DELETE |
120 |
Send Add_Item KEY_F1 VK_F1 |
121 |
Send Add_Item KEY_F2 VK_F2 |
122 |
Send Add_Item KEY_F3 VK_F3 |
123 |
Send Add_Item KEY_F4 VK_F4 |
124 |
Send Add_Item KEY_F5 VK_F5 |
125 |
Send Add_Item KEY_F6 VK_F6 |
126 |
Send Add_Item KEY_F7 VK_F7 |
127 |
Send Add_Item KEY_F8 VK_F8 |
128 |
Send Add_Item KEY_F9 VK_F9 |
129 |
Send Add_Item KEY_F10 VK_F10 |
130 |
Send Add_Item KEY_F11 VK_F11 |
131 |
Send Add_Item KEY_F12 VK_F12 |
132 |
// KEY_A .. KEY_Z |
133 |
Send Add_Item KEY_SPACE VK_SPACE |
134 |
Send Add_Item KSPACE VK_SPACE |
135 |
// KEY_0 .. KEY_9 |
136 |
Send Add_Item KEY_PLUS VK_ADD |
137 |
Send Add_Item KEY_MINUS VK_SUBTRACT |
138 |
// Send Add_Item KEY_EQUAL |
139 |
// Send Add_Item KEY_BACK_SLASH |
140 |
Send Add_Item KEY_SLASH VK_DIVIDE |
141 |
Send Add_Item KHELP VK_HELP |
142 |
// |
143 |
// |
144 |
// Logical keys |
145 |
Send Add_Item KSAVE_RECORD VK_F2 |
146 |
// Send Add_Item KDELETE_RECORD Key_Shift+Key_F2 |
147 |
Send Add_Item KEXIT_FUNCTION VK_F3 |
148 |
// Send Add_Item KEXIT_APPLICATION Key_Alt+Key_F4 |
149 |
Send Add_Item KPROMPT VK_F4 |
150 |
// Send Add_Item KPRINT_SCREEN Key_Shift+Key_F4 |
151 |
Send Add_Item KCLEAR VK_F5 |
152 |
// Send Add_Item KREFRESH_SCREEN Key_Shift+Key_F5 |
153 |
Send Add_Item KSWITCH VK_F6 |
154 |
// Send Add_Item KSWITCH_BACK Key_Shift+Key_F6 |
155 |
Send Add_Item KFIND VK_F9 |
156 |
Send Add_Item KFIND_PREVIOUS VK_F7 |
157 |
Send Add_Item KFIND_NEXT VK_F8 |
158 |
// Send Add_Item KSUPER_FIND Key_Shift+Key_F9 |
159 |
// Send Add_Item KSUPER_FIND_PREVIOUS Key_Shift+Key_F7 |
160 |
// Send Add_Item KSUPER_FIND_NEXT Key_Shift+Key_F8 |
161 |
Send Add_Item KACTION_BAR VK_F10 |
162 |
Send Add_Item KENTER VK_RETURN |
163 |
Send Add_Item KUPARROW VK_UP |
164 |
Send Add_Item KDOWNARROW VK_DOWN |
165 |
Send Add_Item KLEFTARROW VK_LEFT |
166 |
Send Add_Item KRIGHTARROW VK_RIGHT |
167 |
Send Add_Item KSCROLL_BACK VK_PRIOR |
168 |
Send Add_Item KSCROLL_FORWARD VK_NEXT |
169 |
// Send Add_Item KSCROLL_LEFT |
170 |
// Send Add_Item KSCROLL_RIGHT |
171 |
Send Add_Item KBEGIN_OF_LINE VK_HOME |
172 |
Send Add_Item KEND_OF_LINE VK_END |
173 |
Send Add_Item KNEXT_ITEM VK_TAB |
174 |
// Send Add_Item KPREVIOUS_ITEM |
175 |
Send Add_Item KDELETE_CHARACTER VK_DELETE |
176 |
// Send Add_Item KERASE_END_OF_LINE |
177 |
Send Add_Item KBACK_SPACE VK_BACK |
178 |
Send Add_Item KCANCEL VK_ESCAPE |
179 |
// Send Add_Item KBEGIN_OF_PANEL |
180 |
// Send Add_Item KEND_OF_PANEL |
181 |
// Send Add_Item KBEGIN_OF_DATA |
182 |
// Send Add_Item KEND_OF_DATA |
183 |
// Send Add_Item KWORD_LEFT |
184 |
// Send Add_Item KWORD_RIGHT |
185 |
Send Add_Item KINSERT VK_INSERT |
186 |
// Send Add_Item KCLEAR_AND_RETURN |
187 |
// Send Add_Item KADD_MODE |
188 |
// Send Add_Item KPASTE |
189 |
// Send Add_Item KCOPY |
190 |
// Send Add_Item KCUT |
191 |
// Send Add_Item KCLEAR_ALL |
192 |
// Send Add_Item KMOUSE |
193 |
// Send Add_Item KMARK |
194 |
// Send Add_Item KZOOM |
195 |
// Send Add_Item KCLOSE_PANEL |
196 |
End_Procedure // FillKeyArray |
197 |
|
198 |
//Finish object construction |
199 |
Procedure End_Construct_Object |
200 |
Send FillKeyArray |
201 |
Forward Send End_Construct_Object |
202 |
End_Procedure // End_Construct_Object |
203 |
End_Class // cKeyList |
204 |
|
205 |
|
206 |
Class cVirtualKeyboard Is a Array |
207 |
|
208 |
//Insert your Properties here. |
209 |
Procedure Construct_Object |
210 |
Forward Send Construct_Object |
211 |
Property Integer piVirtualKeyCode Public 0 |
212 |
Property Integer piVirtualShiftState Public 0 |
213 |
Property Integer piTranslatedKeyCode Public 0 // private |
214 |
Property Integer piTranslatedShiftState Public 0 // private |
215 |
|
216 |
Object oKeyArray Is a cKeyList |
217 |
End_Object // KeyArray |
218 |
End_Procedure // Construct_Object |
219 |
|
220 |
|
221 |
// bVK is the virtual key code |
222 |
// bKeyUP is (true) if key UP or (false) for a key down |
223 |
// bKeyExtended must be true for non ascii keys |
224 |
// bKeyUP is optional |
225 |
// bKeyExtended is optional |
226 |
// Note: You will normally use the key procedure to send individual |
227 |
// keystrokes. |
228 |
Procedure KeyStroke Integer iVK Boolean bKeyUP Boolean bKeyExtended |
229 |
Integer iVoid |
230 |
DWord dwFlags |
231 |
Boolean bMyKeyUP |
232 |
Boolean bMyKeyExtended |
233 |
Move (False) To bMyKeyUP |
234 |
Move 0 To dwFlags |
235 |
If (Num_Arguments>=2) Begin |
236 |
Move bKeyUP To bMyKeyUP |
237 |
End |
238 |
If (Num_Arguments=3) Begin |
239 |
Move bKeyExtended To bMyKeyExtended |
240 |
End |
241 |
|
242 |
If (bMyKeyUP) Begin |
243 |
Move (dwFlags Ior KEYEVENTF_KEYUP) To dwFlags |
244 |
End |
245 |
If (bMyKeyExtended) Begin |
246 |
Move (dwFlags Ior KEYEVENTF_EXTENDEDKEY) To dwFlags |
247 |
End |
248 |
Move (fkbdevent(iVK,0,dwFlags,0)) To iVoid |
249 |
End_Procedure // KeyStroke |
250 |
|
251 |
|
252 |
// You can use this method to send dataflex keycombinations to |
253 |
// the object that currently has the focus |
254 |
// |
255 |
Procedure Key Integer iKeyValue |
256 |
Boolean bShift |
257 |
Boolean bControl |
258 |
Boolean bAlt |
259 |
Boolean bExt |
260 |
Integer iVK |
261 |
Move (iKeyValue Iand Key_Shift) To bShift |
262 |
Move (iKeyValue Iand Key_Ctrl) To bControl |
263 |
Move (iKeyValue Iand Key_Alt) To bAlt |
264 |
Move (bControl Or bAlt) To bExt |
265 |
If (bControl) Begin |
266 |
Move (iKeyValue - Key_Ctrl) To iKeyValue |
267 |
Send KeyStroke VK_CONTROL 0 bExt |
268 |
End |
269 |
If (bAlt) Begin |
270 |
Move (iKeyValue - Key_Alt) To iKeyValue |
271 |
Send KeyStroke VK_MENU 0 bExt |
272 |
End |
273 |
If (bShift) Begin |
274 |
Move (iKeyValue - Key_Shift) To iKeyValue |
275 |
Send KeyStroke VK_SHIFT 0 bExt |
276 |
End |
277 |
|
278 |
Get DFKeyToVirtual iKeyValue To iVK |
279 |
Send KeyStroke iVK 0 bExt // key down |
280 |
Send KeyStroke iVK 1 bExt // key up |
281 |
|
282 |
If (bShift) Begin |
283 |
Send KeyStroke VK_SHIFT 0 bExt |
284 |
End |
285 |
If (bAlt) Begin |
286 |
Send KeyStroke VK_MENU 0 bExt |
287 |
End |
288 |
If (bControl) Begin |
289 |
Send KeyStroke VK_CONTROL 1 bExt |
290 |
End |
291 |
End_Procedure // Key |
292 |
|
293 |
|
294 |
// Translates a character to the corresponding virtual-key code |
295 |
// And shift state For the current keyboard. |
296 |
// If successful you can get the data from the functions |
297 |
// translatedKeyCode |
298 |
// and |
299 |
// translatedShiftState |
300 |
// |
301 |
// Note: this only works for standard keyboards. |
302 |
Function TranslateKey Integer iKey Returns Boolean |
303 |
Integer bSuccess |
304 |
Short uResult |
305 |
Integer iVK |
306 |
Integer iShift |
307 |
|
308 |
Move (False) To bSuccess |
309 |
Move (fVkKeyScan(iKey)) To uResult |
310 |
Move (LOW_WORD_MASK Ior uResult) To iVK |
311 |
Move (HIGH_WORD_MASK Ior uResult) To iShift |
312 |
If ((iVK=-1) And (iShift=-1)) Begin |
313 |
Error 555 "Unable to translate key" |
314 |
Set piTranslatedKeyCode To 0 |
315 |
Set piTranslatedShiftState To 0 |
316 |
End |
317 |
Else Begin |
318 |
Move (true) To bSuccess |
319 |
Set piTranslatedKeyCode To iVK |
320 |
Set piTranslatedShiftState To iShift |
321 |
End |
322 |
Function_Return bSuccess |
323 |
End_Function // TranslateKey |
324 |
|
325 |
|
326 |
|
327 |
Function StringToKeyboard String sValue Returns Integer |
328 |
Boolean bErr |
329 |
Boolean bWasLastCharUC |
330 |
Boolean bIsCharUC |
331 |
Integer iPos |
332 |
Integer iChar |
333 |
Integer iLength |
334 |
String sChar |
335 |
Integer iVK |
336 |
Integer iShift |
337 |
|
338 |
Move (Length(sValue)) To iLength |
339 |
Move (False) To bErr |
340 |
Move (False) To bWasLastCharUC |
341 |
If (iLength>0) Begin |
342 |
For iPos From 1 To iLength |
343 |
Move (Mid(sValue,1,iPos)) To sChar |
344 |
Move (Ascii(sChar)) To iChar |
345 |
If (TranslateKey(Self,iChar)) Begin |
346 |
Get TranslatedKeyCode To iVK |
347 |
Get TranslatedShiftState To iShift |
348 |
End |
349 |
Else Begin |
350 |
Showln "Error translating key <" sChar "> :: " iChar |
351 |
End |
352 |
Move (Uppercase(sChar)=sChar) To bIsCharUC |
353 |
If ((bIsCharUC<>bWasLastCharUC) And (bIsCharUC)) Begin |
354 |
Send KeyStroke VK_SHIFT |
355 |
End |
356 |
Send KeyStroke iVK |
357 |
Send KeyStroke iVK (True) |
358 |
|
359 |
If ((bIsCharUC<>bWasLastCharUC) And (bIsCharUC)) Begin |
360 |
Send KeyStroke VK_SHIFT (True) |
361 |
End |
362 |
|
363 |
Move bIsCharUC To bWasLastCharUC |
364 |
Loop |
365 |
End |
366 |
Function_Return (bErr) |
367 |
End_Function // StringToKeyboard |
368 |
|
369 |
// Use the method Write to write a string to the virtual keyboard |
370 |
// You can add multiple parameters |
371 |
// |
372 |
Procedure Write |
373 |
Integer iVoid |
374 |
Integer iArg |
375 |
String sValue |
376 |
For iArg From 1 To Num_Arguments |
377 |
Movestr iArg& To sValue |
378 |
Get StringToKeyboard sValue To iVoid |
379 |
Loop |
380 |
End_Procedure // Write |
381 |
|
382 |
// Private |
383 |
// This function translates an unshifted DF key (no Shift/control/Alt) |
384 |
// into its scancode equivalent. |
385 |
// |
386 |
Function DFKeyToVirtual Integer iKey Returns Integer |
387 |
Integer iVK |
388 |
Get MapDFToVirtual Of (oKeyArray(Self)) iKey To iVK |
389 |
Function_Return iVK |
390 |
End_Function // DFKeyToVirtual |
391 |
|
392 |
|
393 |
// private |
394 |
Function TranslatedKeyCode Returns Integer |
395 |
Function_Return (piTranslatedKeyCode(Self)) |
396 |
End_Function // TranslatedKeyCode |
397 |
|
398 |
// private |
399 |
Function TranslatedShiftState Returns Integer |
400 |
Function_Return (piTranslatedShiftState(Self)) |
401 |
End_Function // TranslatedShiftState |
402 |
|
403 |
|
404 |
|
405 |
//Finish object construction |
406 |
Procedure End_Construct_Object |
407 |
Forward Send End_Construct_Object |
408 |
End_Procedure // End_Construct_Object |
409 |
End_Class // cVirtualKeyboard |
410 |
|
411 |
|
412 |
Object oVirtualKeyboard Is a cVirtualKeyboard |
413 |
Move Self To ghoVirtualKeyboard |
414 |
End_Object // oVirtualKeyboard |