I have a program for testing circuit boards. A test is performed when the operator clicks the appropriate button or presses the space bar when the button has focus.
My problem is that whilst the test is running I want to prevent further, accidental key presses from causing the routine from running again. Disabling the button doesn't work because I guess subsequent keystrokes are being held in the buffer. In the PB Console Compiler I could flush the keyboard buffer using "Input Flush". I haven't been able to find an equivalent way of doing this in Firefly/PBwin.
Any ideas or pointers please?
- Paul
I would just disable the button to prevent any keyboard presses, or clicks.
so if they push a button the first command executed for the button call back would be...
FF_Control_Disable (hWndControl)
then when the test is completed, re-enable the control again ...
FF_Control_Enable (hWndControl )
hope this helps.
PAul
Thanks Paul.
I tried this but the routine still fires twice. I also tried shifting the focus immediately after it's clicked but I still get the same effect. I guess this is because the key press remains in the buffer and when the control is re-enabled after the test is completed the button picks it up. My reasoning is that if I can flush the buffer before re-enabling the button my troubles will be over ... but we are talking Windows here!
Hi Paul,
I have tried to replicate your result with a simple sample project but I can not get it to receive any more clicks once the button is disabled. Windows is not supposed to sent BN_CLICKED notifications to windows that are disabled. It is in the BN_CLICKED handler that you are disabling the button, right?
Here is the code that I used (Form with two command buttons and a label)
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
Static p As Long
Incr p
FF_Control_SetText HWND_FORM1_LABEL1, Str$(p)
FF_Control_Disable HWND_FORM1_COMMAND1
' Call function that will do the processing. Keystrokes may continue to
' be pressed during this time.
Sleep 5000
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_COMMAND2_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
FF_Control_Enable HWND_FORM1_COMMAND1
SetFocus HWND_FORM1_COMMAND1
End Function
Hi Paul -
Thanks for the usual excellent support.
Essentially the only difference between your code and mine seems to be that for each routine I've re-enabled the control from inside its own BN_CLICKED handler after the test routine has finished thus -
Function FORM1_COMMAND1_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
Static p As Long
Incr p
FF_Control_SetText HWND_FORM1_LABEL1, Str$(p)
FF_Control_Disable HWND_FORM1_COMMAND1
' Call function that will do the processing. Keystrokes may continue to
' be pressed during this time.
Sleep 5000
FF_Control_Enable HWND_FORM1_COMMAND1
SetFocus HWND_FORM1_COMMAND1
End Function
This seems to be what's causing my problem. Maybe I'm doing something fundamentally silly here?
Now that I know your code works I'll re-consider my interface so that I use a second control to re-enable the first.
- Paul
I wonder if you Postmessage a user defined message rather than re-enabling from inside BN_CLICKED. The theory would be that it would allow BN_CLICKED to fully finish prior to re-enabling the control. I haven't tested it but maybe it's worth a try.
%MSG_USER_ENABLE = %WM_USER + 100
Function FORM1_COMMAND1_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
Static p As Long
Incr p
FF_Control_SetText HWND_FORM1_LABEL1, Str$(p)
FF_Control_Disable HWND_FORM1_COMMAND1
' Call function that will do the processing. Keystrokes may continue to
' be pressed during this time.
Sleep 5000
' Post a message to re-enable the command button
PostMessage hWndForm, %MSG_USER_ENABLE, 0, 0
End Function
Function FORM1_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Select Case wMsg
Case %MSG_USER_ENABLE
FF_Control_Enable HWND_FORM1_COMMAND1
SetFocus HWND_FORM1_COMMAND1
End Select
End Function
Hi Paul -
Alas this doesn't work :(
- Paul