LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Numeric slide and keyboard control

Hi,

 

I noticed that with a numeric slide control, if the user grabs the control with the mouse and moves it around, there will be a series of EVENT_VAL_CHANGED events followed by a final EVENT_COMMIT when they release the mouse button, which is what I expect.  However, if a crafty user decides to move the slider around by pushing and holding the arrow keys on the keyboard, there is a series of EVENT_VAL_CHANGED events, but after each EVENT_VAL_CHANGED there is also an EVENT_COMMIT (in addition to all the EVENT_KEYPRESS events).  This is a problem for me as while the code that responds to the EVENT_VAL_CHANGED is fast, the code that responds to EVENT_COMMIT is somewhat slower.  This is not a problem when moving the slider with the mouse but is quite noticable when moving the slider by holding down the arrow keys on the keyboard.  Is there any way to modify this behavior?  Thanks.

0 Kudos
Message 1 of 3
(3,137 Views)

Since the EVENT_KEYPRESS occurs before the EVENT_COMMIT, you can use this to avoid your slow code in the EVENT_COMMIT case. If the EVENT_KEYPRESS occurs, then set a flag that will be read and reset in the EVENT_COMMIT case. The code below demonstrates this behavior.

 

static int arrowKeyUsed = 0; 

int CVICALLBACK sliderCB (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	switch (event)
	{
		case EVENT_VAL_CHANGED:
			//fast code
			DebugPrintf("EVENT_VAL_CHANGED\n");
			break;
		case EVENT_COMMIT:
			if(arrowKeyUsed == 1)
			{
				DebugPrintf("EVENT_COMMIT\tarrowKeyUsed = 1\n"); 
				arrowKeyUsed = 0;
			}
			else
			{
				DebugPrintf("EVENT_COMMIT\tarrowKeyUsed = 0\n");
				//slow code
				Delay(1);
			}
			break;
		case EVENT_KEYPRESS:
			DebugPrintf("EVENT_KEYPRESS");
			if(eventData1 == VAL_DOWN_ARROW_VKEY || eventData1 == VAL_UP_ARROW_VKEY);
			{
				DebugPrintf("\tarrowKeyUsed");
				arrowKeyUsed = 1;
			}
			DebugPrintf("\n");
			break;	
	}
	return 0;
}

 

National Instruments
0 Kudos
Message 2 of 3
(3,132 Views)

Hi D. Biel,

 

Thanks for the reply.  I considered a solution along those lines, but my concern was that then the EVENT_COMMIT "slow code" would never run, when the intention is that it should run just once when the user releases the arrow key.  I suppose I could rig something up but I was wondering if there was a more elegant solution.

 

 

0 Kudos
Message 3 of 3
(3,129 Views)