Advertisement
ZoriaRPG

ZScript Keyboard Handler

Jun 26th, 2018
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. int key_repeat = 0;
  2. void DoKey(int buffer)
  3. {
  4.     int keymap[KEY_MAX]; int tempchar; int modofiers[9];
  5.     while(Game->TypingMode)
  6.     {
  7.        
  8.         if ( key_repeat > 0 )
  9.         {
  10.             --key_repeat;
  11.             continue;
  12.         }
  13.         memset(modifiers,0); //clear this iteration
  14.         for ( int q = 0; q < KEY_MAX; ++q )
  15.         {
  16.             if ( Input->ReadKey[q] ) tempchar = keymap[q];
  17.             key_repeat = KEY_REPEAT_DUR;
  18.            
  19.             if ( tempchar !IsModifier() )
  20.                 break;
  21.             else
  22.             {
  23.                 switch(tempkey)
  24.                 {
  25.                     case KEY_LSHIFT:
  26.                     {
  27.                         modifiers[LSHIFT] = 1; break;
  28.                     }
  29.                     case KEY_RSHIFT:
  30.                     {
  31.                         modifiers[RSHIFT] = 1; break;
  32.                     }
  33.                     case KEY_LCTL:
  34.                     {
  35.                         modifiers[LCTL] = 1; break;
  36.                     }
  37.                     case KEY_RCTL:
  38.                     {
  39.                         modifiers[RCTL] = 1; break;
  40.                     }
  41.                     case KEY_LALT:
  42.                     {
  43.                         modifiers[LALT] = 1; break;
  44.                     }
  45.                     case KEY_RALT:
  46.                     {
  47.                         modifiers[RALT] = 1; break;
  48.                     }
  49.                     case KEY_APPLE:
  50.                     {
  51.                         modifiers[APPLE] = 1; break;
  52.                     }
  53.                     case KEY_OPT:
  54.                     {
  55.                         modifiers[OPT] = 1; break;
  56.                     }
  57.                     case KEY_WIN:
  58.                     {
  59.                         modifiers[WIN] = 1; break;
  60.                     }
  61.                 }
  62.             } //Don't break or continue here!
  63.                        
  64.         }
  65.        
  66.         //actions to do with tempkey
  67.        
  68.         //forward to KeyProcess(tempchar, buffer)!
  69.        
  70.         //chars
  71.        
  72.             //modified
  73.        
  74.             //not modified
  75.        
  76.         //special
  77.             //backspace
  78.             //function and other
  79.        
  80.         //Exit Typing Mode
  81.         if ( tempchar == KEY_ESC ) Game->TypingMode = false;
  82.        
  83.        
  84.         Waitframe();
  85. }
  86.  
  87. void KeypressProcess(int chr, int buffer)
  88. {
  89.     //actions to do with tempkey
  90.        
  91.         //chars
  92.        
  93.             //modified
  94.        
  95.             //not modified
  96.        
  97.         //special
  98.             //backspace
  99.             //function and other
  100.    
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement