LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ASCII to character conversion

Hello, I would like to convert ASCII value into character that I got from eventData1.
Since eventData1 acquired from EVENT_KEYPRESS is integer,  I need to convert it back to char.
Could anyone help?

int CVICALLBACK go_cmd (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
char

 switch (event)
  {
  case EVENT_KEYPRESS:
   
   input = eventData1;
   
   
   //if (eventData1 = 'a')
   //InsertTextBoxLine (panelHandle, PANEL_CMD, gLine, "A");
  SetCtrlVal (panelHandle, PANEL_CMD, input_char);
  
   /*switch (eventData1)
   {
   case 'a':
   InsertTextBoxLine (panelHandle, PANEL_CMD, gLine++, "A");
   //SetCtrlVal (panelHandle, PANEL_CMD, "A");
   break;
   
   case VAL_DOWN_ARROW_VKEY:
   QuitUserInterface(0);
   break;
   
   case VAL_ENTER_VKEY:
   enter_pressed();
   break;
   
   default:
   break;

   }
  */
  }
 return 0;
}

 
0 Kudos
Message 1 of 5
(3,840 Views)

I couldn't find a way to delete a thread that i posted.

Problem is solved using fmt. please disregard my prev thread. thanks.

 

Justin

0 Kudos
Message 2 of 5
(3,824 Views)

Sorry, duplicated post! Smiley Sad

Message Edited by Roberto Bozzolo on 01-06-2006 12:19 AM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 3 of 5
(3,824 Views)

Sorry, duplicated post!   Smiley Sad

Message Edited by Roberto Bozzolo on 01-06-2006 12:19 AM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 5
(3,824 Views)

Justinlee, detecting the keys hit by the user is a little bit more complicated than you imagine. I suggest that you studi keyfiltr.prj sample located in <cvidir>\samples\userint to undestand how keyboard events are treated in control callbacks. As you can see in the code:

        /* eventData1 contains the keypress value represented as a 4-byte    */
        /* integer consisting of 3 fields, 0x00MMVVAA:                       */
        /*    MM = the modifier key                                          */
        /*    VV = the virtual key, masks defined in userint.h               */
        /*    AA = the ASCII key                                             */
        /* eventData2 is a pointer to an integer which holds the actual key  */
        /* value.  This pointer can be used to change the value of the key   */
        /* before the control processes it.                                  */
        asciiCode = eventData1 & VAL_ASCII_KEY_MASK;
        virtualKey = eventData1 & VAL_VKEY_MASK;
        modifierKey = eventData1 & VAL_MODIFIER_KEY_MASK;

Once separated the three components of the character received, you can test individually each of them as in the following examples:
if (virtualKey == VAL_ESC_VKEY) {               // Tests the 'Esc' key
if ((modifierKey == VAL_MENUKEY_MODIFIER) && (virtualKey == VAL_END_VKEY)) {             // Tests Ctrl+End combination
if (asciiCode == 'a') {                // Tests individual characters
 
asciiCode can be translated into corresponding character:
DebugPrintf ("Character pressed = %c\n", asciiCode);
 
Hope this helps
Roberto

Message Edited by Roberto Bozzolo on 01-06-2006 12:21 AM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 5 of 5
(3,827 Views)