LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

No KeyPress triggered if mouse button is held on control

Solved!
Go to solution

Hello All,

I'm trying to catch held/auto repeating keyboard inputs at the same time I'm clicking a ring slide control, to change the meaning of the slide input like a Shift key.  (in fact I'd love to use the Shift key, but it doesn't seem to trigger keypress events at any time so I've resorted to letter keys).  I check for the keypress event inside the panel callback, it fires fine if no mouse btns are pressed, or if they are pressed on indicator or decorations on the panel.  But as soon as I click any control with an active input, all keypress events stop until the the mouse button is lifted, then keypress starts firing again, completely defeating the purpose of simultaneous inputs.  I put test code in the slide control callback, and it doesn't get keypress events either if the mouse button is down, though it does if it has focus but the mouse button is up.

 

Any ideas?  I am still using ver 6.0 if that make a difference, trying to get IT to upgrade me to 8.0 but trying to get something done on the old version while I wait.

 

Ken

0 Kudos
Message 1 of 8
(4,434 Views)

It's strange what you are saying about the shift key: keypress event is perfectly able to trap combination of keys. As an example, this snipped of code traps Ctrl+Home, Ctrl+End and Esc keys combinations:

 

    switch (event) {
        case EVENT_KEYPRESS:
        // eventData1: a 4-byte integer consisting of 3 fields: 0x00MMVVAA
        // MM = the modifier key, VV = the virtual key, AA = the ASCII key
        // key masks are defined in "userint.h"
            virtualKey = eventData1 & VAL_VKEY_MASK;
            modifierKey = eventData1 & VAL_MODIFIER_KEY_MASK;

            if (modifierKey == VAL_MENUKEY_MODIFIER && virtualKey == VAL_HOME_VKEY) {

                 // Some code here to handle Ctrl+Home combination

            }
            else if (modifierKey == VAL_MENUKEY_MODIFIER && virtualKey == VAL_END_VKEY) {

                 // Some code here to handle Ctrl+End combination

            }
            else if (virtualKey == VAL_ESC_VKEY) {

                 // Some code here to handle Esc key

            }
            break;
    }

 

This code works even in CVI6 (actually I've taken it from an old application of mine developed in that release).



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?
0 Kudos
Message 2 of 8
(4,423 Views)

Thanks, I meant that Shift alone doesn't trigger a keypress event.  I believe it does modify the event data when combined with another keypress.  I'm trying to sense whether a single key is continuously pressed, shift or otherwise, at the same time I'm activating a control with the mouse.

 

Ken

0 Kudos
Message 3 of 8
(4,406 Views)

Hi Roberto,

I think what Ken is referring to is the fact that if the user presses only the <Shift> key then no keypress event is sent. He's right. Modifier keys by themselves do not constitute a key press.

 

Ken,

 

I'm going to look into the problem you described (no keypress events while the mouse is down) and letyou know what I find. I was able to reproduce that behavior in the latest version of CVI, so upgrading at this point will not be of much help. I'll keep you posted.

 

Luis

0 Kudos
Message 4 of 8
(4,404 Views)
Solution
Accepted by topic author KenbobC

I didn't understand exactly what Ken was referring to. Let's try another approach: a control callback fires a LEFT_CLICK or COMMIT event even it the shift key is pressed, so Ken could trap the desired event and test then the keyboard state, this way:

 

    if (event == EVENT_LEFT_CLICK) {
        GetGlobalMouseState (NULL, NULL, NULL, NULL, NULL, &keys);
        if (keys && VAL_SHIFT_MODIFIER) {
            MessagePopup ("Event", "Shift key was 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?
0 Kudos
Message 5 of 8
(4,386 Views)

Thanks Roberto, thats the ticket!  I hadn't thought to look from the mouse side, and didn't know about GetGlobalMouseState.  Now my primary keyboard input can be <Shift>, which I wanted anyway, and which works smoothly with the mouse.  A few other keys still aren't truly simultaneous with mousing, but I added some persistence timers to fake it, and they are less critical anyway.  I'd still like to know if there is a proper way to get non-modifier key events while mousing a control, but I'm good for now.

 

Thanks again,

Ken

0 Kudos
Message 6 of 8
(4,376 Views)

Hello again, Ken.

 

I'm glad you have your preferred solution in place. (Roberto comes through, as usual Smiley Wink )

 

As far as the other issue is concerned, I looked into and found that it was really a design limitation of CVI that disallows keypress from being sent while the mouse button is being pressed. It's not all mouse clicks that cause it. As you yourself identified earlier, it's mouse clicks in an input area of a control. Basically it's any click that starts a particular action on a control: dragging a graph cursor, moving a scrollbar, selecting text, etc... these are called tracking loops, and they have some complicated implications on event processing, since internally they essentially represent a nested event loop.

 

To make a long story short, I looked into the feasibility of dispatching the full set of CVI events from within a tracking loop, and it really wasn't possible. Not without incurring a very large risk of inadvertently changing the behavior of existing programs. Therefore... I'm really glad that you managed to solve your problem using Roberto's solution Smiley Happy

 

Luis

0 Kudos
Message 7 of 8
(4,349 Views)

Luis,

Thanks for following up, it sounds like you did much more digging than I would have been able to.  And now I can feel more comfortable with my kluge w/o fretting that there is some way to do it properly.

 

Ken

0 Kudos
Message 8 of 8
(4,346 Views)