Advertisement
ZoriaRPG

Keyboard Reading Example

Sep 19th, 2019
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include "std.zh"
  2. hero script kb_read_test
  3. {
  4.     const int BUFFER_SIZE = 500;
  5.     void run()
  6.     {
  7.  
  8.         int StringBuffer[BUFFER_SIZE];
  9.         TraceS("Input String Test:\n");
  10.         Game->TypingMode = true;
  11.         int index;
  12.         while(!Input->Key[KEY_ENTER])
  13.         {
  14.                         for(int i = KEY_A; i<=KEY_SPACE; ++i)
  15.             {
  16.                
  17.                 if(Input->ReadKey[i])
  18.                 {
  19.                     if(i == KEY_BACKSPACE && index > 0)
  20.                     {
  21.                         --index;
  22.                         StringBuffer[index] = 0;
  23.                     }
  24.                     else
  25.                     {
  26.                         if ( index < ( BUFFER_SIZE-1 ) )
  27.                         {
  28.                             LogPrint("KeyToChar is: %d \n", KeyToChar(i));
  29.                             StringBuffer[index] = KeyToChar(i);
  30.                             ++index;
  31.                         }
  32.                     }
  33.                    
  34.                     TraceS(StringBuffer);
  35.                 }
  36.                         }
  37.                         Waitframe();
  38.         }
  39.         TraceNL();
  40.         StringBuffer[index+1] = '\n';
  41.         TraceS(StringBuffer);
  42.         Game->TypingMode = false;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement