This example translates virtual scan code and effective shift state for [ to Unicode.

#include <stdio.h>
#include <unikbd.h>

int main(void) {

   KHAND          kbdhandle;
   KBDNAME       *kbd_name;
   ULONG          mode     =  0;

   USHIFTSTATE    Uss      = {0};/* indicates no shift keys, toggle keys,
                                    dead keys, or layer keys are pressed.
                                  */
   VSCAN          v_scan;
   BYTE           makebreak;

   UniChar        uc;
   VDKEY          vk;
   BYTE           bscan;

   APIRET         rc;

   /***************************************************/
   /* Create a keyboard handle for US keyboard layout */
   /***************************************************/

   kbd_name = (UniChar*)L"us";

   rc = UniCreateKeyboard( &kbdhandle, kbd_name, mode );

   if ( rc != ULS_SUCCESS ) {
      printf("UniCreateKeyboard error: return code = %u\n", rc );
      return 1;
   }

   v_scan         = 0x5B;           /*PM scan code for [          */
   makebreak      = KEYEV_MAKE;     /*indicate key is pressed down*/

   rc = UniUpdateShiftState( kbdhandle, &Uss, v_scan, makebreak );

   if ( rc != ULS_SUCCESS ) {
      printf("UniUpdateShiftState error: return code = %u\n", rc );
      return 1;
   }

   rc = UniTranslateKey( kbdhandle, Uss.Effective, v_scan, &uc, &vk, &bscan );

   if ( rc != ULS_SUCCESS ) {
      printf("UniTranslateKey error: return code = %u\n", rc );
      return 1;
   }

   return ULS_SUCCESS;

}


[Back: UniTranslateKey - Remarks]
[Next: UniTranslateKey - Topics]