I was reading an old post about capturing keystrokes in a textbox. The answer given was to subclass the control.
It's easy enough to capture the last character typed in, as long as it was typed at the end (code example below).
Another way to approach the problem is to use the %EN_Change notification - compare the previous content of the textbox to the content of the textbox when %EN_change is called.
The approach can certainly be used to reject keystrokes which result in an undesired/desired textbox content - such as limiting it to numbers, letters, or special formats.
Figuring out which non-character keys were pressed (arrow keys, shift/control, ...) or highlighting or copy/paste wouldn't be so straight-forward.
But just because I don't see an immediate answer, doesn't mean someone else hasn't played with it to see what could be done.
Has anyone come up with an attempt at a generalized solution?
If not, perhaps I'll play with it and see what kind of an answer I can dream up - then ask for the forum for critique.
I can't say as I have any pressing reason to do it - just looking at alternative solutions.
It's easy enough to capture the last character typed in, as long as it was typed at the end (code example below).
Another way to approach the problem is to use the %EN_Change notification - compare the previous content of the textbox to the content of the textbox when %EN_change is called.
The approach can certainly be used to reject keystrokes which result in an undesired/desired textbox content - such as limiting it to numbers, letters, or special formats.
Figuring out which non-character keys were pressed (arrow keys, shift/control, ...) or highlighting or copy/paste wouldn't be so straight-forward.
But just because I don't see an immediate answer, doesn't mean someone else hasn't played with it to see what could be done.
Has anyone come up with an attempt at a generalized solution?
Code:
#Compile Exe #Dim All #Include "win32api.inc" Function PBMain() As Long Local hDlg As Dword Dialog New Pixels, 0, "Button Test",300,300,200,200, %WS_OverlappedWindow To hDlg Control Add TextBox, hDlg, 200,"Push", 50,40,100,20 Control Add Label, hDlg, 300,"", 50,70,100,20 Dialog Show Modal hDlg Call DlgProc End Function CallBack Function DlgProc() As Long Local NewTxt$ If Cb.Msg = %WM_Command And Cb.Ctl = 200 And Cb.CtlMsg = %EN_Change Then Control Get Text Cb.Hndl, 200 To NewTxt$ Control Set Text Cb.Hndl, 300, Right$(NewTxt$,1) End If End Function
I can't say as I have any pressing reason to do it - just looking at alternative solutions.
Comment