Hi,
Am I correct in supposing that to check what key the user pressed in an edit box, you montor the %WM_KEYDOWN event? In which case where does this code have to be entered in the code generated by firefly, or alter it from within pb?
I am looking to intercept the key that has been pressed by the user before it is written to the edit box.
Also, how can I use the ENTER KEY to shift focus rather than using the TAB key.
Thanks
Chris
Here's the CUSTOM code for one of my edit boxes, where it eats the ENTER key and replaces it by shifting the focus to the next control:
Function DLGCONFIGURE_TXTPORT_CUSTOM (ControlIndex As Long, hWndForm As Dword, hWndControl As Dword, wMsg As Long, wParam As Dword, lParam As Long) As Long
On Error Resume Next
Function = 0
If wMsg = 135 And wParam = %VK_RETURN Then
' Replace return with tab character.
Control Set Focus HWND_DLGCONFIGURE, IDC_DLGCONFIGURE_CBDEFWHITELIST
Function = 1
End If
End Function
You will need to change the handles to match your forms and controls, but apart from that it's generic.
Andrew
FireFly makes this kind of stuff very easy. Normally, you would have to subclass the textbox and filter out the keys. In FireFly you just respond to the WM_CHAR message. The following example filters out all "A" and "a" characters (note: you don't have to use the Chr$ function, but I used it here for clarity):
Function FORM1_TEXT1_WM_CHAR ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
chCharCode As Long, _ ' character code
lKeyData As Long _ ' key data
) As Long
'Keys to filter
Select Case Chr$(chCharCode)
Case "A", "a"
Function = 1: Exit Function
End Select
End Function
Hi,
Thanks for the help - I appreciate it.
Chris
Your Thread title mentioned trapping F1 keys too, so if you still need help on those:
Process in the CUSTOM for the form:
Local hlpinfo As HELPINFO Ptr 'Pointer for Context Help Structure
Select Case wMsg
Case %WM_HELP
hlpinfo= lParam
Select Case @hlpinfo.hItemHandle
Case [HWND of Control you want to process]
Case Else
End Select
Function= %TRUE
Case %Other_WM_Cases
End Select
Also, if you add the Context Help button (WS_EX_CONTEXTHELP Style, Little ? by Min/Max buttons) it sends these when controls are clicked after pushing it too.
Picking up an old treed here, and I wonder if this is possible to do for a ComboBox? I would need to trap if the user hit ENTER and not only tab him to next control but also excute some code based of what is in the text portion of the control, or possible a current selection in the list.
The thing is, I use the auto completion code posted by Roger and it works great. It's just that each item in the combo is related to a bunch of data displayed in a ListBox. Updating this list as the user types and get a match is just to slow and cumbersome. So I like to wait doing so until the user hits Enter to comfirm the autocompleted selection.
The code above posted by kazmax doesn't work in a combo... hitting enter doesn't seem to trigger anything.
/Joakim