LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Key Press Down

I currently have two command buttons that when held down basically count a variable up or down. I want to do the same kind of thing with the up and down arrows on the keyboard. I know how to do something when the key is pressed but how would you know if it is held down or not? Is there a similar thing to the mouse LEFT_CLICK_UP for the keyboard?

Thanks
Message 1 of 5
(4,065 Views)
Could you not just assign shortcut keys (of Up Arrow and Down Arrow, without modifiers) to your existing command buttons? Not exactly what you wanted I know but it might be close enough. (The auto-repeat function will keep generating EVENT_COMMIT callbacks.)

JR
0 Kudos
Message 2 of 5
(4,042 Views)
That might work but I was using:
EVENT_LEFT_CLICK:
EVENT_LEFT_MOUSE_UP:
EVENT_MOUSE_MOVE:

not COMMIT because commit waits until a full click while I was doing the operation while the mouse button was held down on the button.
0 Kudos
Message 3 of 5
(4,037 Views)
Nick,

You can use the EVENT_KEYPRESS callback on your button, although the limitation of this is that the command button must have the current control focus in order to work. I.e. the user will have to click on the button once before using the keyboard. You may be able to work around this in a couple of different ways depending on the setup of your GUI.

On an event keypress, the EventData1 and EventData2 values are used to determine what key was pressed. See the following functions that you must use to determine the key pressed:

KeyPressEventIsLeadByte
KeyPressEventIsTrailByte
GetKeyPressEventCharacter
0 Kudos
Message 4 of 5
(4,027 Views)
Yeah right now I have this working:

case EVENT_KEYPRESS:
//get number of key pressed
keyCode = GetKeyPressEventVirtualKey(eventData2);//GetKeyPressEventCharacter(eventData2);
if (keyCode == 0x600) //up arrow
{
MessagePopup("Key Tapped", "Up Arrow was tapped");
}
else if (keyCode == 0x700) //down arrow
{
MessagePopup("Key Tapped", "Down Arrow was tapped");
}
break;

This lets me know when a key was pressed down, is there a way to tell when it is done being pressed down or is that not easily done?
0 Kudos
Message 5 of 5
(4,021 Views)