home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 14 / MacFormat n. 14 (Spain) / MacFormat 14.bin / Shareware Internet / HyperCard / XCMD Docs / CompileIt! Source Code / KeyIsDown(KeyCode) < prev    next >
Encoding:
Text File  |  1995-08-19  |  1.2 KB  |  50 lines

  1. global TheKeys:P
  2. function KeyIsDown KeyCode
  3.   if KeyCode = "?" then return "KeyIsDown, a simple solution to one of the things that apple left out of HyperCard. Syntax: KeyIsDown <<keyCode>> result:True or false"
  4.   put NewPtr(32) into TheKeys
  5.   GetKeys theKeys@
  6.   get GetBit(KeyCode)
  7.   disposPtr TheKeys
  8.   return (it=1)
  9. end KeyIsDown
  10.  
  11. function GetBit bit
  12.   get bit
  13.   put it div 8 into TheByte
  14.   put it mod 8 into TheBit
  15.   put TheKeys@.charType[TheByte] into h
  16.   put CharToNum(h) into j
  17.   if j ≥ 128 then
  18.     put 1 before ggg
  19.     subtract 128 from j
  20.   else put 0 before ggg
  21.   if j ≥ 64 then
  22.     put 1 before ggg
  23.     subtract 64 from j
  24.   else put 0 before ggg
  25.   if j ≥ 32 then
  26.     put 1 before ggg
  27.     subtract 32 from j
  28.   else put 0 before ggg
  29.   if j ≥ 16 then
  30.     put 1 before ggg
  31.     subtract 16 from j
  32.   else put 0 before ggg
  33.   if j ≥ 8 then
  34.     put 1 before ggg
  35.     subtract 8 from j
  36.   else put 0 before ggg
  37.   if j ≥ 4 then
  38.     put 1 before ggg
  39.     subtract 4 from j
  40.   else put 0 before ggg
  41.   if j ≥ 2 then
  42.     put 1 before ggg
  43.     subtract 2 from j
  44.   else put 0 before ggg
  45.   if j ≥ 1 then
  46.     put 1 before ggg
  47.     subtract 1 from j
  48.   else put 0 before ggg
  49.   return char TheBit+1 of ggg
  50. end GetBit