win32gr.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Pierre Muller
  4. This unit implements an the hooks needed for the win32 graph unit.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit win32gr;
  19. interface
  20. procedure SetGraphHooks;
  21. procedure UnsetGraphHooks;
  22. implementation
  23. uses
  24. windows,
  25. drivers,
  26. graph;
  27. var
  28. InputHandle : Handle;
  29. StoredControlKeyState : longint;
  30. lastir : INPUT_RECORD;
  31. const
  32. StoredChar : boolean = false;
  33. const
  34. KeyToAsciiCode : array [0..255] of char =
  35. (
  36. { 00 } #0,
  37. { 01 VK_LBUTTON } #0,
  38. { 02 VK_RBUTTON } #0,
  39. { 03 VK_CANCEL } #0,
  40. { 04 VK_MBUTTON } #0,
  41. { 05 unassigned } #0,
  42. { 06 unassigned } #0,
  43. { 07 unassigned } #0,
  44. { 08 VK_BACK } #8,
  45. { 09 VK_TAB } #9,
  46. { 0A unassigned } #0,
  47. { 0B unassigned } #0,
  48. { 0C VK_CLEAR ?? } #0,
  49. { 0D VK_RETURN } #13,
  50. { 0E unassigned } #0,
  51. { 0F unassigned } #0,
  52. { 10 VK_SHIFT } #0,
  53. { 11 VK_CONTROL } #0,
  54. { 12 VK_MENU (Alt key) } #0,
  55. { 13 VK_PAUSE } #0,
  56. { 14 VK_CAPITAL (Caps Lock) } #0,
  57. { 15 Reserved for Kanji systems} #0,
  58. { 16 Reserved for Kanji systems} #0,
  59. { 17 Reserved for Kanji systems} #0,
  60. { 18 Reserved for Kanji systems} #0,
  61. { 19 Reserved for Kanji systems} #0,
  62. { 1A unassigned } #0,
  63. { 1B VK_ESCAPE } #27,
  64. { 1C Reserved for Kanji systems} #0,
  65. { 1D Reserved for Kanji systems} #0,
  66. { 1E Reserved for Kanji systems} #0,
  67. { 1F Reserved for Kanji systems} #0,
  68. { 20 VK_SPACE} ' ',
  69. { 21 VK_PRIOR (PgUp) } #0,
  70. { 22 VK_NEXT (PgDown) } #0,
  71. { 23 VK_END } #0,
  72. { 24 VK_HOME } #0,
  73. { 25 VK_LEFT } #0,
  74. { 26 VK_UP } #0,
  75. { 27 VK_RIGHT } #0,
  76. { 28 VK_DOWN } #0,
  77. { 29 VK_SELECT ??? } #0,
  78. { 2A OEM specific !! } #0,
  79. { 2B VK_EXECUTE } #0,
  80. { 2C VK_SNAPSHOT } #0,
  81. { 2D VK_INSERT } #0,
  82. { 2E VK_DELETE } #0,
  83. { 2F VK_HELP } #0,
  84. { 30 VK_0 '0' } '0',
  85. { 31 VK_1 '1' } '1',
  86. { 32 VK_2 '2' } '2',
  87. { 33 VK_3 '3' } '3',
  88. { 34 VK_4 '4' } '4',
  89. { 35 VK_5 '5' } '5',
  90. { 36 VK_6 '6' } '6',
  91. { 37 VK_7 '7' } '7',
  92. { 38 VK_8 '8' } '8',
  93. { 39 VK_9 '9' } '9',
  94. { 3A unassigned } #0,
  95. { 3B unassigned } #0,
  96. { 3C unassigned } #0,
  97. { 3D unassigned } #0,
  98. { 3E unassigned } #0,
  99. { 3F unassigned } #0,
  100. { 40 unassigned } #0,
  101. { 41 VK_A 'A' } 'A',
  102. { 42 VK_B 'B' } 'B',
  103. { 43 VK_C 'C' } 'C',
  104. { 44 VK_D 'D' } 'D',
  105. { 45 VK_E 'E' } 'E',
  106. { 46 VK_F 'F' } 'F',
  107. { 47 VK_G 'G' } 'G',
  108. { 48 VK_H 'H' } 'H',
  109. { 49 VK_I 'I' } 'I',
  110. { 4A VK_J 'J' } 'J',
  111. { 4B VK_K 'K' } 'K',
  112. { 4C VK_L 'L' } 'L',
  113. { 4D VK_M 'M' } 'M',
  114. { 4E VK_N 'N' } 'N',
  115. { 4F VK_O 'O' } 'O',
  116. { 50 VK_P 'P' } 'P',
  117. { 51 VK_Q 'Q' } 'Q',
  118. { 52 VK_R 'R' } 'R',
  119. { 53 VK_S 'S' } 'S',
  120. { 54 VK_T 'T' } 'T',
  121. { 55 VK_U 'U' } 'U',
  122. { 56 VK_V 'V' } 'V',
  123. { 57 VK_W 'W' } 'W',
  124. { 58 VK_X 'X' } 'X',
  125. { 59 VK_Y 'Y' } 'Y',
  126. { 5A VK_Z 'Z' } 'Z',
  127. { 5B unassigned } #0,
  128. { 5C unassigned } #0,
  129. { 5D unassigned } #0,
  130. { 5E unassigned } #0,
  131. { 5F unassigned } #0,
  132. { 60 VK_NUMPAD0 NumKeyPad '0' } '0',
  133. { 61 VK_NUMPAD1 NumKeyPad '1' } '1',
  134. { 62 VK_NUMPAD2 NumKeyPad '2' } '2',
  135. { 63 VK_NUMPAD3 NumKeyPad '3' } '3',
  136. { 64 VK_NUMPAD4 NumKeyPad '4' } '4',
  137. { 65 VK_NUMPAD5 NumKeyPad '5' } '5',
  138. { 66 VK_NUMPAD6 NumKeyPad '6' } '6',
  139. { 67 VK_NUMPAD7 NumKeyPad '7' } '7',
  140. { 68 VK_NUMPAD8 NumKeyPad '8' } '8',
  141. { 69 VK_NUMPAD9 NumKeyPad '9' } '9',
  142. { 6A VK_MULTIPLY } #0,
  143. { 6B VK_ADD } #0,
  144. { 6C VK_SEPARATOR } #0,
  145. { 6D VK_SUBSTRACT } #0,
  146. { 6E VK_DECIMAL } #0,
  147. { 6F VK_DIVIDE } #0,
  148. { 70 VK_F1 'F1' } #0,
  149. { 71 VK_F2 'F2' } #0,
  150. { 72 VK_F3 'F3' } #0,
  151. { 73 VK_F4 'F4' } #0,
  152. { 74 VK_F5 'F5' } #0,
  153. { 75 VK_F6 'F6' } #0,
  154. { 76 VK_F7 'F7' } #0,
  155. { 77 VK_F8 'F8' } #0,
  156. { 78 VK_F9 'F9' } #0,
  157. { 79 VK_F10 'F10' } #0,
  158. { 7A VK_F11 'F11' } #0,
  159. { 7B VK_F12 'F12' } #0,
  160. { 7C VK_F13 } #0,
  161. { 7D VK_F14 } #0,
  162. { 7E VK_F15 } #0,
  163. { 7F VK_F16 } #0,
  164. { 80 VK_F17 } #0,
  165. { 81 VK_F18 } #0,
  166. { 82 VK_F19 } #0,
  167. { 83 VK_F20 } #0,
  168. { 84 VK_F21 } #0,
  169. { 85 VK_F22 } #0,
  170. { 86 VK_F23 } #0,
  171. { 87 VK_F24 } #0,
  172. { 88 unassigned } #0,
  173. { 89 VK_NUMLOCK } #0,
  174. { 8A VK_SCROLL } #0,
  175. { 8B unassigned } #0,
  176. { 8C unassigned } #0,
  177. { 8D unassigned } #0,
  178. { 8E unassigned } #0,
  179. { 8F unassigned } #0,
  180. { 90 unassigned } #0,
  181. { 91 unassigned } #0,
  182. { 92 unassigned } #0,
  183. { 93 unassigned } #0,
  184. { 94 unassigned } #0,
  185. { 95 unassigned } #0,
  186. { 96 unassigned } #0,
  187. { 97 unassigned } #0,
  188. { 98 unassigned } #0,
  189. { 99 unassigned } #0,
  190. { 9A unassigned } #0,
  191. { 9B unassigned } #0,
  192. { 9C unassigned } #0,
  193. { 9D unassigned } #0,
  194. { 9E unassigned } #0,
  195. { 9F unassigned } #0,
  196. { A0 unassigned } #0,
  197. { A1 unassigned } #0,
  198. { A2 unassigned } #0,
  199. { A3 unassigned } #0,
  200. { A4 unassigned } #0,
  201. { A5 unassigned } #0,
  202. { A6 unassigned } #0,
  203. { A7 unassigned } #0,
  204. { A8 unassigned } #0,
  205. { A9 unassigned } #0,
  206. { AA unassigned } #0,
  207. { AB unassigned } #0,
  208. { AC unassigned } #0,
  209. { AD unassigned } #0,
  210. { AE unassigned } #0,
  211. { AF unassigned } #0,
  212. { B0 unassigned } #0,
  213. { B1 unassigned } #0,
  214. { B2 unassigned } #0,
  215. { B3 unassigned } #0,
  216. { B4 unassigned } #0,
  217. { B5 unassigned } #0,
  218. { B6 unassigned } #0,
  219. { B7 unassigned } #0,
  220. { B8 unassigned } #0,
  221. { B9 unassigned } #0,
  222. { BA OEM specific } #0,
  223. { BB OEM specific } #0,
  224. { BC OEM specific } #0,
  225. { BD OEM specific } #0,
  226. { BE OEM specific } #0,
  227. { BF OEM specific } #0,
  228. { C0 OEM specific } #0,
  229. { C1 unassigned } #0,
  230. { C2 unassigned } #0,
  231. { C3 unassigned } #0,
  232. { C4 unassigned } #0,
  233. { C5 unassigned } #0,
  234. { C6 unassigned } #0,
  235. { C7 unassigned } #0,
  236. { C8 unassigned } #0,
  237. { C9 unassigned } #0,
  238. { CA unassigned } #0,
  239. { CB unassigned } #0,
  240. { CC unassigned } #0,
  241. { CD unassigned } #0,
  242. { CE unassigned } #0,
  243. { CF unassigned } #0,
  244. { D0 unassigned } #0,
  245. { D1 unassigned } #0,
  246. { D2 unassigned } #0,
  247. { D3 unassigned } #0,
  248. { D4 unassigned } #0,
  249. { D5 unassigned } #0,
  250. { D6 unassigned } #0,
  251. { D7 unassigned } #0,
  252. { D8 unassigned } #0,
  253. { D9 unassigned } #0,
  254. { DA unassigned } #0,
  255. { DB OEM specific } #0,
  256. { DC OEM specific } #0,
  257. { DD OEM specific } #0,
  258. { DE OEM specific } #0,
  259. { DF OEM specific } #0,
  260. { E0 OEM specific } #0,
  261. { E1 OEM specific } #0,
  262. { E2 OEM specific } #0,
  263. { E3 OEM specific } #0,
  264. { E4 OEM specific } #0,
  265. { E5 unassigned } #0,
  266. { E6 OEM specific } #0,
  267. { E7 unassigned } #0,
  268. { E8 unassigned } #0,
  269. { E9 OEM specific } #0,
  270. { EA OEM specific } #0,
  271. { EB OEM specific } #0,
  272. { EC OEM specific } #0,
  273. { ED OEM specific } #0,
  274. { EE OEM specific } #0,
  275. { EF OEM specific } #0,
  276. { F0 OEM specific } #0,
  277. { F1 OEM specific } #0,
  278. { F2 OEM specific } #0,
  279. { F3 OEM specific } #0,
  280. { F4 OEM specific } #0,
  281. { F5 OEM specific } #0,
  282. { F6 unassigned } #0,
  283. { F7 unassigned } #0,
  284. { F8 unassigned } #0,
  285. { F9 unassigned } #0,
  286. { FA unassigned } #0,
  287. { FB unassigned } #0,
  288. { FC unassigned } #0,
  289. { FD unassigned } #0,
  290. { FE unassigned } #0,
  291. { FF unassigned } #0
  292. );
  293. KeyToQwertyScan : array [0..255] of byte =
  294. (
  295. { 00 } 0,
  296. { 01 VK_LBUTTON } 0,
  297. { 02 VK_RBUTTON } 0,
  298. { 03 VK_CANCEL } 0,
  299. { 04 VK_MBUTTON } 0,
  300. { 05 unassigned } 0,
  301. { 06 unassigned } 0,
  302. { 07 unassigned } 0,
  303. { 08 VK_BACK } $E,
  304. { 09 VK_TAB } $F,
  305. { 0A unassigned } 0,
  306. { 0B unassigned } 0,
  307. { 0C VK_CLEAR ?? } 0,
  308. { 0D VK_RETURN } $1C,
  309. { 0E unassigned } 0,
  310. { 0F unassigned } 0,
  311. { 10 VK_SHIFT } 0,
  312. { 11 VK_CONTROL } 0,
  313. { 12 VK_MENU (Alt key) } 0,
  314. { 13 VK_PAUSE } 0,
  315. { 14 VK_CAPITAL (Caps Lock) } 0,
  316. { 15 Reserved for Kanji systems} 0,
  317. { 16 Reserved for Kanji systems} 0,
  318. { 17 Reserved for Kanji systems} 0,
  319. { 18 Reserved for Kanji systems} 0,
  320. { 19 Reserved for Kanji systems} 0,
  321. { 1A unassigned } 0,
  322. { 1B VK_ESCAPE } $1,
  323. { 1C Reserved for Kanji systems} 0,
  324. { 1D Reserved for Kanji systems} 0,
  325. { 1E Reserved for Kanji systems} 0,
  326. { 1F Reserved for Kanji systems} 0,
  327. { 20 VK_SPACE} $39,
  328. { 21 VK_PRIOR (PgUp) } $49,
  329. { 22 VK_NEXT (PgDown) } $51,
  330. { 23 VK_END } $4F,
  331. { 24 VK_HOME } $47,
  332. { 25 VK_LEFT } $4B,
  333. { 26 VK_UP } $48,
  334. { 27 VK_RIGHT } $4D,
  335. { 28 VK_DOWN } $50,
  336. { 29 VK_SELECT ??? } 0,
  337. { 2A OEM specific !! } 0,
  338. { 2B VK_EXECUTE } 0,
  339. { 2C VK_SNAPSHOT } 0,
  340. { 2D VK_INSERT } $52,
  341. { 2E VK_DELETE } $53,
  342. { 2F VK_HELP } 0,
  343. { 30 VK_0 '0' } 11,
  344. { 31 VK_1 '1' } 2,
  345. { 32 VK_2 '2' } 3,
  346. { 33 VK_3 '3' } 4,
  347. { 34 VK_4 '4' } 5,
  348. { 35 VK_5 '5' } 6,
  349. { 36 VK_6 '6' } 7,
  350. { 37 VK_7 '7' } 8,
  351. { 38 VK_8 '8' } 9,
  352. { 39 VK_9 '9' } 10,
  353. { 3A unassigned } 0,
  354. { 3B unassigned } 0,
  355. { 3C unassigned } 0,
  356. { 3D unassigned } 0,
  357. { 3E unassigned } 0,
  358. { 3F unassigned } 0,
  359. { 40 unassigned } 0,
  360. { 41 VK_A 'A' } $1E,
  361. { 42 VK_B 'B' } $30,
  362. { 43 VK_C 'C' } $2E,
  363. { 44 VK_D 'D' } $20,
  364. { 45 VK_E 'E' } $12,
  365. { 46 VK_F 'F' } $21,
  366. { 47 VK_G 'G' } $22,
  367. { 48 VK_H 'H' } $23,
  368. { 49 VK_I 'I' } $17,
  369. { 4A VK_J 'J' } $24,
  370. { 4B VK_K 'K' } $25,
  371. { 4C VK_L 'L' } $26,
  372. { 4D VK_M 'M' } $32,
  373. { 4E VK_N 'N' } $31,
  374. { 4F VK_O 'O' } $18,
  375. { 50 VK_P 'P' } $19,
  376. { 51 VK_Q 'Q' } $10,
  377. { 52 VK_R 'R' } $13,
  378. { 53 VK_S 'S' } $1F,
  379. { 54 VK_T 'T' } $14,
  380. { 55 VK_U 'U' } $16,
  381. { 56 VK_V 'V' } $2F,
  382. { 57 VK_W 'W' } $11,
  383. { 58 VK_X 'X' } $2D,
  384. { 59 VK_Y 'Y' } $15,
  385. { 5A VK_Z 'Z' } $2C,
  386. { 5B unassigned } 0,
  387. { 5C unassigned } 0,
  388. { 5D unassigned } 0,
  389. { 5E unassigned } 0,
  390. { 5F unassigned } 0,
  391. { 60 VK_NUMPAD0 NumKeyPad '0' } 11,
  392. { 61 VK_NUMPAD1 NumKeyPad '1' } 2,
  393. { 62 VK_NUMPAD2 NumKeyPad '2' } 3,
  394. { 63 VK_NUMPAD3 NumKeyPad '3' } 4,
  395. { 64 VK_NUMPAD4 NumKeyPad '4' } 5,
  396. { 65 VK_NUMPAD5 NumKeyPad '5' } 6,
  397. { 66 VK_NUMPAD6 NumKeyPad '6' } 7,
  398. { 67 VK_NUMPAD7 NumKeyPad '7' } 8,
  399. { 68 VK_NUMPAD8 NumKeyPad '8' } 9,
  400. { 69 VK_NUMPAD9 NumKeyPad '9' } 10,
  401. { 6A VK_MULTIPLY } 0,
  402. { 6B VK_ADD } 0,
  403. { 6C VK_SEPARATOR } 0,
  404. { 6D VK_SUBSTRACT } 0,
  405. { 6E VK_DECIMAL } 0,
  406. { 6F VK_DIVIDE } 0,
  407. { 70 VK_F1 'F1' } $3B,
  408. { 71 VK_F2 'F2' } $3C,
  409. { 72 VK_F3 'F3' } $3D,
  410. { 73 VK_F4 'F4' } $3E,
  411. { 74 VK_F5 'F5' } $3F,
  412. { 75 VK_F6 'F6' } $40,
  413. { 76 VK_F7 'F7' } $41,
  414. { 77 VK_F8 'F8' } $42,
  415. { 78 VK_F9 'F9' } $43,
  416. { 79 VK_F10 'F10' } $44,
  417. { 7A VK_F11 'F11' } $57,
  418. { 7B VK_F12 'F12' } $58,
  419. { 7C VK_F13 } 0,
  420. { 7D VK_F14 } 0,
  421. { 7E VK_F15 } 0,
  422. { 7F VK_F16 } 0,
  423. { 80 VK_F17 } 0,
  424. { 81 VK_F18 } 0,
  425. { 82 VK_F19 } 0,
  426. { 83 VK_F20 } 0,
  427. { 84 VK_F21 } 0,
  428. { 85 VK_F22 } 0,
  429. { 86 VK_F23 } 0,
  430. { 87 VK_F24 } 0,
  431. { 88 unassigned } 0,
  432. { 89 VK_NUMLOCK } 0,
  433. { 8A VK_SCROLL } 0,
  434. { 8B unassigned } 0,
  435. { 8C unassigned } 0,
  436. { 8D unassigned } 0,
  437. { 8E unassigned } 0,
  438. { 8F unassigned } 0,
  439. { 90 unassigned } 0,
  440. { 91 unassigned } 0,
  441. { 92 unassigned } 0,
  442. { 93 unassigned } 0,
  443. { 94 unassigned } 0,
  444. { 95 unassigned } 0,
  445. { 96 unassigned } 0,
  446. { 97 unassigned } 0,
  447. { 98 unassigned } 0,
  448. { 99 unassigned } 0,
  449. { 9A unassigned } 0,
  450. { 9B unassigned } 0,
  451. { 9C unassigned } 0,
  452. { 9D unassigned } 0,
  453. { 9E unassigned } 0,
  454. { 9F unassigned } 0,
  455. { A0 unassigned } 0,
  456. { A1 unassigned } 0,
  457. { A2 unassigned } 0,
  458. { A3 unassigned } 0,
  459. { A4 unassigned } 0,
  460. { A5 unassigned } 0,
  461. { A6 unassigned } 0,
  462. { A7 unassigned } 0,
  463. { A8 unassigned } 0,
  464. { A9 unassigned } 0,
  465. { AA unassigned } 0,
  466. { AB unassigned } 0,
  467. { AC unassigned } 0,
  468. { AD unassigned } 0,
  469. { AE unassigned } 0,
  470. { AF unassigned } 0,
  471. { B0 unassigned } 0,
  472. { B1 unassigned } 0,
  473. { B2 unassigned } 0,
  474. { B3 unassigned } 0,
  475. { B4 unassigned } 0,
  476. { B5 unassigned } 0,
  477. { B6 unassigned } 0,
  478. { B7 unassigned } 0,
  479. { B8 unassigned } 0,
  480. { B9 unassigned } 0,
  481. { BA OEM specific } 0,
  482. { BB OEM specific } 0,
  483. { BC OEM specific } 0,
  484. { BD OEM specific } 0,
  485. { BE OEM specific } 0,
  486. { BF OEM specific } 0,
  487. { C0 OEM specific } 0,
  488. { C1 unassigned } 0,
  489. { C2 unassigned } 0,
  490. { C3 unassigned } 0,
  491. { C4 unassigned } 0,
  492. { C5 unassigned } 0,
  493. { C6 unassigned } 0,
  494. { C7 unassigned } 0,
  495. { C8 unassigned } 0,
  496. { C9 unassigned } 0,
  497. { CA unassigned } 0,
  498. { CB unassigned } 0,
  499. { CC unassigned } 0,
  500. { CD unassigned } 0,
  501. { CE unassigned } 0,
  502. { CF unassigned } 0,
  503. { D0 unassigned } 0,
  504. { D1 unassigned } 0,
  505. { D2 unassigned } 0,
  506. { D3 unassigned } 0,
  507. { D4 unassigned } 0,
  508. { D5 unassigned } 0,
  509. { D6 unassigned } 0,
  510. { D7 unassigned } 0,
  511. { D8 unassigned } 0,
  512. { D9 unassigned } 0,
  513. { DA unassigned } 0,
  514. { DB OEM specific } 0,
  515. { DC OEM specific } 0,
  516. { DD OEM specific } 0,
  517. { DE OEM specific } 0,
  518. { DF OEM specific } 0,
  519. { E0 OEM specific } 0,
  520. { E1 OEM specific } 0,
  521. { E2 OEM specific } 0,
  522. { E3 OEM specific } 0,
  523. { E4 OEM specific } 0,
  524. { E5 unassigned } 0,
  525. { E6 OEM specific } 0,
  526. { E7 unassigned } 0,
  527. { E8 unassigned } 0,
  528. { E9 OEM specific } 0,
  529. { EA OEM specific } 0,
  530. { EB OEM specific } 0,
  531. { EC OEM specific } 0,
  532. { ED OEM specific } 0,
  533. { EE OEM specific } 0,
  534. { EF OEM specific } 0,
  535. { F0 OEM specific } 0,
  536. { F1 OEM specific } 0,
  537. { F2 OEM specific } 0,
  538. { F3 OEM specific } 0,
  539. { F4 OEM specific } 0,
  540. { F5 OEM specific } 0,
  541. { F6 unassigned } 0,
  542. { F7 unassigned } 0,
  543. { F8 unassigned } 0,
  544. { F9 unassigned } 0,
  545. { FA unassigned } 0,
  546. { FB unassigned } 0,
  547. { FC unassigned } 0,
  548. { FD unassigned } 0,
  549. { FE unassigned } 0,
  550. { FF unassigned } 0
  551. );
  552. { this procedure allows to hook keyboard messages }
  553. function fvisioncharmessagehandler (Window: hwnd; AMessage, WParam,
  554. LParam: Longint): Longint;
  555. var
  556. ir : INPUT_RECORD;
  557. NumWritten : dword;
  558. vKey : byte;
  559. scancode : integer;
  560. ach, ch : array[0..1] of char;
  561. IsExtended : boolean;
  562. begin
  563. fvisioncharmessagehandler:=0;
  564. if (AMessage = WM_CHAR) or (AMessage = WM_SYSCHAR) then
  565. begin
  566. if StoredChar then
  567. begin
  568. ach[0]:=chr(wparam and $ff);
  569. ach[1]:=#0;
  570. CharToOem(@ach,@ch);
  571. {$ifdef DEBUG}
  572. Write('key ',hexstr(lastir.Event.KeyEvent.wVirtualKeyCode,2));
  573. Write(' scan ',hexstr(lastir.Event.KeyEvent.wVirtualScanCode,2));
  574. if lastir.Event.KeyEvent.bKeyDown then
  575. writeln(' pressed')
  576. else
  577. writeln(' released');
  578. Writeln('char ',ach[0],'(',ch[0],')',' $',hexstr(wparam,2));
  579. {$endif DEBUG}
  580. Lastir.Event.KeyEvent.AsciiChar:=ch[0];
  581. WriteConsoleInput(InputHandle,lastir,1,NumWritten);
  582. StoredChar:=false;
  583. end
  584. else
  585. begin
  586. {$ifdef DEBUG}
  587. Writeln('char ',chr(wparam and $ff),' $',hexstr(wparam,2),' ignored');
  588. {$endif DEBUG}
  589. ach[0]:=chr(wparam and $ff);
  590. ach[1]:=#0;
  591. CharToOem(@ach,@ch);
  592. {$ifdef DEBUG}
  593. Write('key ',hexstr(lastir.Event.KeyEvent.wVirtualKeyCode,2));
  594. Write(' scan ',hexstr(lastir.Event.KeyEvent.wVirtualScanCode,2));
  595. if lastir.Event.KeyEvent.bKeyDown then
  596. writeln(' pressed')
  597. else
  598. writeln(' released');
  599. Writeln('char ',ach[0],'(',ch[0],')',' $',hexstr(wparam,2));
  600. {$endif DEBUG}
  601. Lastir.Event.KeyEvent.AsciiChar:=ch[0];
  602. WriteConsoleInput(InputHandle,lastir,1,NumWritten);
  603. StoredChar:=false;
  604. end;
  605. exit;
  606. end;
  607. if StoredChar then
  608. begin
  609. {$ifdef DEBUG}
  610. Write('key ',hexstr(lastir.Event.KeyEvent.wVirtualKeyCode,2));
  611. Write(' scan ',hexstr(lastir.Event.KeyEvent.wVirtualScanCode,2));
  612. if lastir.Event.KeyEvent.bKeyDown then
  613. writeln(' pressed')
  614. else
  615. writeln(' released');
  616. Writeln('char ',ach[0],'(',ch[0],')',' $',hexstr(wparam,2));
  617. {$endif DEBUG}
  618. WriteConsoleInput(InputHandle,lastir,1,NumWritten);
  619. StoredChar:=false;
  620. end;
  621. fillchar(ir,sizeof(ir),#0);
  622. ir.EventType:=KEY_EVENT;
  623. with ir.Event.KeyEvent do
  624. begin
  625. vKey:=WParam and $ff;
  626. wRepeatCount:=lparam and $ffff;
  627. IsExtended:=(lParam and (1 shl 24))<>0;
  628. if (AMessage = WM_KEYDOWN) or (AMessage = WM_SYSKEYDOWN) then
  629. bKeyDown:=true;
  630. wVirtualKeyCode:=vKey;
  631. AsciiChar:=KeyToAsciiCode[vKey];
  632. if AsciiChar<>#0 then
  633. begin
  634. { Use lower chars }
  635. if ((StoredControlKeyState and SHIFT_PRESSED)=0) and
  636. ((wVirtualKeyCode>=VK_A) and (wVirtualKeyCode<=VK_Z)) then
  637. AsciiChar:=chr(ord(AsciiChar) + ord('a')-ord('A'));
  638. if bKeyDown then
  639. StoredChar:=true;
  640. end;
  641. scancode:=KeyToQwertyScan[vKey];
  642. if scancode>0 then
  643. wVirtualScanCode:=scancode;
  644. case vKey of
  645. VK_SHIFT :
  646. if bKeyDown then
  647. StoredControlKeyState:= StoredControlKeyState or SHIFT_PRESSED
  648. else
  649. StoredControlKeyState:= StoredControlKeyState and not SHIFT_PRESSED;
  650. VK_CONTROL :
  651. begin
  652. if IsExtended then
  653. begin
  654. if bKeyDown then
  655. StoredControlKeyState:= StoredControlKeyState or RIGHT_CTRL_PRESSED
  656. else
  657. StoredControlKeyState:= StoredControlKeyState and not RIGHT_CTRL_PRESSED;
  658. end
  659. else if bKeyDown then
  660. StoredControlKeyState:= StoredControlKeyState or LEFT_CTRL_PRESSED
  661. else
  662. StoredControlKeyState:= StoredControlKeyState and not LEFT_CTRL_PRESSED;
  663. end;
  664. VK_MENU :
  665. begin
  666. if IsExtended then
  667. begin
  668. if bKeyDown then
  669. StoredControlKeyState:= StoredControlKeyState or RIGHT_ALT_PRESSED
  670. else
  671. StoredControlKeyState:= StoredControlKeyState and not RIGHT_ALT_PRESSED;
  672. end
  673. else if bKeyDown then
  674. StoredControlKeyState:= StoredControlKeyState or LEFT_ALT_PRESSED
  675. else
  676. StoredControlKeyState:= StoredControlKeyState and not LEFT_ALT_PRESSED;
  677. end;
  678. end;
  679. dwControlKeyState:=StoredControlKeyState;
  680. end;
  681. if not StoredChar then
  682. begin
  683. {$ifdef DEBUG}
  684. Write('key ',hexstr(ir.Event.KeyEvent.wVirtualKeyCode,2));
  685. Write(' scan ',hexstr(ir.Event.KeyEvent.wVirtualScanCode,2));
  686. if ir.Event.KeyEvent.bKeyDown then
  687. writeln(' pressed')
  688. else
  689. writeln(' released');
  690. {$endif DEBUG}
  691. WriteConsoleInput(InputHandle,ir,1,NumWritten);
  692. { still copy for use for special keys not registered }
  693. Lastir:=ir;
  694. end
  695. else
  696. Lastir:=ir;
  697. end;
  698. { this procedure allows to hook mouse messages }
  699. function fvisionmousemessagehandler (Window: hwnd; AMessage, WParam,
  700. LParam: Longint): Longint;
  701. var
  702. ir : INPUT_RECORD;
  703. NumWritten : dword;
  704. begin
  705. fvisionmousemessagehandler:=0;
  706. ir.EventType:=_MOUSE_EVENT;
  707. with ir.Event.MouseEvent do
  708. begin
  709. dwMousePosition.x:=loword(LParam) div SysFontWidth;
  710. dwMousePosition.y:=hiword(LParam) div SysFontHeight;
  711. dwButtonState:=0;
  712. if (wParam and MK_LBUTTON)<>0 then
  713. dwButtonState:=dwButtonState or FROM_LEFT_1ST_BUTTON_PRESSED;
  714. if (wParam and MK_MBUTTON)<>0 then
  715. dwButtonState:=dwButtonState or FROM_LEFT_2ND_BUTTON_PRESSED;
  716. if (wParam and MK_RBUTTON)<>0 then
  717. dwButtonState:=dwButtonState or RIGHTMOST_BUTTON_PRESSED;
  718. end;
  719. WriteConsoleInput(InputHandle,ir,1,NumWritten);
  720. end;
  721. {$ifdef USE_NEW_WNDPROC}
  722. Const
  723. PreviousWindowProc: WndProc = nil;
  724. function FvisionWindowProc(Window: HWnd; AMessage, WParam,
  725. LParam: Longint): Longint; stdcall; export;
  726. begin
  727. case AMessage of
  728. wm_lbuttondown,
  729. wm_rbuttondown,
  730. wm_mbuttondown,
  731. wm_lbuttonup,
  732. wm_rbuttonup,
  733. wm_mbuttonup,
  734. wm_lbuttondblclk,
  735. wm_rbuttondblclk,
  736. wm_mbuttondblclk:
  737. {
  738. This leads to problem, i.e. the menu etc doesn't work any longer
  739. wm_nclbuttondown,
  740. wm_ncrbuttondown,
  741. wm_ncmbuttondown,
  742. wm_nclbuttonup,
  743. wm_ncrbuttonup,
  744. wm_ncmbuttonup,
  745. wm_nclbuttondblclk,
  746. wm_ncrbuttondblclk,
  747. wm_ncmbuttondblclk:
  748. }
  749. { if assigned(mousemessagehandler) then }
  750. FvisionWindowProc:=mousemessagehandler(window,amessage,wparam,lparam);
  751. wm_keydown,
  752. wm_keyup,
  753. wm_syskeydown,
  754. wm_syskeyup,
  755. wm_syschar,
  756. wm_char:
  757. { if assigned(charmessagehandler) then }
  758. FvisionWindowProc:=charmessagehandler(window,amessage,wparam,lparam);
  759. else
  760. FvisionWindowProc:= CallWindowProc(PreviousWindowProc,Window,AMessage,WParam,LParam);
  761. end;
  762. end;
  763. {$endif USE_NEW_WNDPROC}
  764. procedure SetGraphHooks;
  765. begin
  766. {$ifdef USE_NEW_WNDPROC}
  767. If not assigned (PreviousWindowProc) then
  768. PreviousWindowProc:=WndProc(SetWindowLong(MainWindow,GWL_WNDPROC, longint(@fvisionWindowProc)));
  769. {$else not USE_NEW_WNDPROC}
  770. mousemessagehandler:=@fvisionmousemessagehandler;
  771. charmessagehandler:=@fvisioncharmessagehandler;
  772. {$endif USE_NEW_WNDPROC}
  773. InputHandle:=GetStdHandle(STD_INPUT_HANDLE);
  774. end;
  775. procedure UnsetGraphHooks;
  776. begin
  777. mousemessagehandler:=nil;
  778. charmessagehandler:=nil;
  779. {$ifdef USE_NEW_WNDPROC}
  780. SetWindowLong(MainWindow,GWL_WNDPROC, longint(PreviousWindowProc));
  781. PreviousWindowProc:=nil;
  782. {$endif USE_NEW_WNDPROC}
  783. InputHandle:=UnusedHandle;
  784. StoredControlKeyState:=0;
  785. end;
  786. end.
  787. {
  788. $Log$
  789. Revision 1.6 2003-01-12 23:25:51 pierre
  790. * fix win32 graph version compilation failure
  791. Revision 1.5 2002/05/31 13:35:33 pierre
  792. * recognize Enter key with kbEnter
  793. Revision 1.4 2002/05/29 21:20:49 pierre
  794. * better key translations
  795. Revision 1.3 2002/05/29 19:34:27 pierre
  796. * fix other keys
  797. Revision 1.2 2002/05/28 19:12:26 pierre
  798. * fix fvisioncharmessage
  799. Revision 1.1 2002/05/24 09:35:20 pierre
  800. first commit, not fully functional yet
  801. }