LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading USB Keyboard inputs with LabWindows CVI

Hello,

I want to recognize keyboard inputs in our CVI applications. In older applications i used the command "inp(0x60)" to do this, but now we only have usb keyboards, so i search a way to recognize the keystrokes from the usb port.

Can someone help me with this problem?

Greets
0 Kudos
Message 1 of 6
(5,134 Views)
Has your application a panel? If so, its callback could trap the EVENT_KEYPRESS event and get the key(s) being pressed


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 2 of 6
(5,109 Views)
The Application runs on a Windows-PC with normal Flat-screen Monitor and since the latest updates we use an USB-Keyboard instead of an PS2-Keyboard, so the function "inp(0x60)" to scan the PS2-Port no longer runs to scan the key pressed by the user, so we need a new possibility to do so.

P.S. We use an UIR-Surface to visualize our program, if this information is helping someone.

Greets
Falko

Message Edited by Loehnert on 06-25-2007 06:38 AM

0 Kudos
Message 3 of 6
(5,101 Views)

I am sorry, Falko, my use of the word "panel" instead of "window" was misleading...

As I can understand, your application has a user interface (I mean, it's not a "hidden" DLL that simply manages data without user interaction), so you should be able to associate a callback to your main panel either in the UIR editor or programmatically with InstallPanelCallback called after LoadPanel; in that callback you can get keyhits:

int CVICALLBACK PanelCallback (int panel, int event, void *callbackData,
        int eventData1, int eventData2)
{
    int asciiCode;
    int virtualKey;         /* cursor keys, function keys, esc, enter, etc.. */
                            /* are "virtual" keys.                           */
    switch (event)         {
        case EVENT_KEYPRESS:
           /* 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;

           // ..... your code follows

    }
    return 0;
}



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 6
(5,088 Views)
Thanks for your reply Roberto,

but this solution seems to be not working in my application.

My problem is, that the call of the UIR happens in an external library, so i cannot change the source code of the Callback function. Do i have another chance to realize it?

I heard about a simple CVI-command, which manages to read the keyboard input, but i don`t know which it was.

Greetings
Falko
0 Kudos
Message 5 of 6
(5,062 Views)
Hi,
    Maybe function GetKeyState(int nVirtKey)  from  Windows SDK <windows.h>  can help you.
    I use this function for get state of  R-CTRL,R-shift  ... but can be used for any key.

    GetKeyState            http://msdn2.microsoft.com/en-us/library/ms646301.aspx
    GetKeyboardState   http://msdn2.microsoft.com/en-us/library/ms646299.aspx

Examples

#include <windows.h> //must be first include declaration in file
....
//#define KeyModifierState_SHIFT_L 2

//#define KeyModifier_KeyDown (1<<31)
//#define KeyModifier_KeyActiveFlag (1<<0)

unsigned int GetKeyModifierState()
{unsigned int i;
 AllMask=0;
 i=GetKeyState(VK_RSHIFT);                    //get state of Rigth Shift key
 if ((i&KeyModifier_KeyDown)!=0)
  i=1;
  else i=0;
return i;
}

0 Kudos
Message 6 of 6
(5,035 Views)