From: Simon on 6 Apr 2010 08:19 Hi, Here is a small description of what I am trying to do. I have simplified it to... // ---------------------------------- MyDlg dlg; if( IDOK != dlg.DoModal() ) { return; } .... bool left_button = ((GetAsyncKeyState(VK_LBUTTON) & 0x8000) == 0x8000 ); assert( false == left_button ); // << left_button is down // ---------------------------------- After the dialog box is closed, why is the left mouse button down? Is the left button really down? Is there something else I could do to check if the left button is down. Thanks Simon
From: AliR on 6 Apr 2010 08:59 That should do it. Are you having a problem? AliR. "Simon" <bad(a)example.com> wrote in message news:ega26NY1KHA.264(a)TK2MSFTNGP05.phx.gbl... > Hi, > > Here is a small description of what I am trying to do. > I have simplified it to... > > // ---------------------------------- > MyDlg dlg; > if( IDOK != dlg.DoModal() ) > { > return; > } > > ... > > bool left_button = ((GetAsyncKeyState(VK_LBUTTON) & 0x8000) == 0x8000 ); > assert( false == left_button ); // << left_button is down > > // ---------------------------------- > > After the dialog box is closed, why is the left mouse button down? > > Is the left button really down? > > Is there something else I could do to check if the left button is down. > > Thanks > > Simon
From: Simon on 6 Apr 2010 09:28 On 2010/04/06 02:59 PM, AliR wrote: > That should do it. That should do what? > > Are you having a problem? Yes, why is the left button still marked as down when the dialog box is closed. Because if I click on the OK button the dialog box only closes when I release the left button, so why would (GetAsyncKeyState(VK_LBUTTON)& 0x8000) == 0x8000 ) return true. Simon
From: David Ching on 6 Apr 2010 13:39 "Simon" <bad(a)example.com> wrote in message news:#4ARD0Y1KHA.4724(a)TK2MSFTNGP02.phx.gbl... > Because if I click on the OK button the dialog box only closes when I > release the left button, so why would (GetAsyncKeyState(VK_LBUTTON)& > 0x8000) == 0x8000 ) return true. > VK_LBUTTON is always the physical left mouse button, so if you have swapped mouse buttons, you need to check VK_RBUTTON instead: http://msdn.microsoft.com/en-us/library/ms646293%28VS.85%29.aspx Also, it should be OK the way you have it, but just do: if ( GetAsyncKeyState(VK_LBUTTON & 0x8000) ) // don't compare == 0x8000 ; If this still does not work, what if you close the dialog by setting focus to the OK button and use the keyboard? Does it then work? There might be something going on with the dialog's DoModal() as that is a separate message loop running, which might screw up the cached keyboard state (although I understand GetAsyncKeyState doesn't use a cached state, it is supposed to be what the hardware state is at the moment you call it.) -- David
From: Joseph M. Newcomer on 6 Apr 2010 14:13
See below... On Tue, 06 Apr 2010 14:19:57 +0200, Simon <bad(a)example.com> wrote: >Hi, > >Here is a small description of what I am trying to do. >I have simplified it to... > >// ---------------------------------- >MyDlg dlg; >if( IDOK != dlg.DoModal() ) >{ > return; >} > >... > >bool left_button = ((GetAsyncKeyState(VK_LBUTTON) & 0x8000) == 0x8000 ); >assert( false == left_button ); // << left_button is down **** assert( ! left_button); why do you think it is necessary to compare a bool to a bool literal to derive, guess what, a bool value to test? Sloppy programming! Why is it that no one understands that at bool value in and of itself is either true or false, and does not NEED to be compared to true or false? > >// ---------------------------------- > >After the dialog box is closed, why is the left mouse button down? *** Perhaps because you had to click the OK button? And the mouse button is still down? You are essentially seeing the result of the difference between computer speed and human speed; within a few tens to a small integer number of hundreds of microseconds after you have clicked the button, the mouse button state is examined, and according to the instantaneous state, the mouse button is still down, because the message that it has come up has not yet been processed. I find the basic idea of this test more than a little weird, actually. Why would you care if the mouse button was down a few nanoseconds after the DoModal() returns? **** > >Is the left button really down? > >Is there something else I could do to check if the left button is down. **** Please explain why you think this is important. joe **** > >Thanks > >Simon Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm |