TOPIC: Intercept 'enter' key in a control
#76
Intercept 'enter' key in a control 4 Years, 5 Months ago
Hi, there is a way to intercept the 'enter' key when the focus is in a FieldControl ?
In the applications, many users are used to press the 'enter' key, instead of 'tab' key to pass from a field to another in a form. Can I do a similar thing in Suneido too?
 
 
Mauro
 
#78
Re:Intercept 'enter' key in a control 4 Years, 5 Months ago
Other people have asked for this. It is possible, but unfortunately it is not easy.

You need to do something similar to PatternControl GETDLGCODE and CHAR methods, except you would change the body of the CHAR method to set the focus to the next field (instead of just doing killfocus).

You can use SetFocus(GetNextDlgTabItem(...))

We use this in a few places, but only to set the focus to the first control.

See MSDN for information about GetNextDlgTabItem.

One issue with this approach is that it will only handle controls derived from FieldControl.

Another approach is to use SetWindowsHookEx(WH.KEYBOARD but this globally intercepts keyboard events so it is a little dangerous. (ListEditWindow uses this.)
 
 
andrew
 
#81
Re:Intercept 'enter' key in a control 4 Years, 5 Months ago
Thanks for your suggestions. I will try it.
 
 
Mauro
 
#116
Re:Intercept 'enter' key in a control 4 Years, 5 Months ago
I have made my control "Duz" like this:

EditControl{Name: "Duz"

New(style = 0){
super(style WS.VISIBLE | WS.TABSTOP )
.SubClass()
}

GETDLGCODE(wParam){
return wParam is VK.RETURN ? DLGC.WANTALLKEYS : DLGC.WANTCHARS}

CHAR(wParam, lParam){
if (wParam is VK.RETURN)
{
SetFocus(GetNextDlgTabItem(.Hwnd, NULL, false))
return 0
}
return 'callsuper'
}
}

1. Should the WS_TABSTOP style be specified?
2. In the function:

HWND GetNextDlgTabItem(
HWND hDlg,
HWND hCtl,
BOOL bPrevious
);

what should the "hDlg - Handle to the dialog box to be searched." and "hCtl - Handle to the control to be used as the starting point for the search. If this parameter is NULL, the function uses the last (or first) control in the dialog box as the starting point for the search." be?


3. I guess I should use setFocus with the return value ?(If the function succeeds, the return value is the window handle of the previous (or next) control that has the WS_TABSTOP style set.)

What are the parameters for SetFocus

Post edited by: popmilo, at: 2006/03/20 17:52
 
 
#118
Re:Intercept 'enter' key in a control 4 Years, 5 Months ago
If you want this field included in the tabbing, you should use WS.TABSTOP.

hDlg should be the HWND of the parent of this control. Try using: .Window.Hwnd (not sure if this is always correct)

hCtl should just be .Hwnd (the HWND of the current control)

SetFocus just takes a single HWND parameter. You are using it correctly.

Hope that helps!
 
 
andrew
 
#119
Re:Intercept 'enter' key in a control 4 Years, 5 Months ago
YES!!!

This is what does it:

SetFocus(GetNextDlgTabItem(.Window.Hwnd, .Hwnd,false))


This was bugging me for two days, and now its done!
Thank you Andrew!
 
 
#120
Re:Intercept 'enter' key in a control 4 Years, 5 Months ago
I want to thank you, popmilo and andrew, for this solution, because until now I haven't had time for looking for it. It seems to work well! ;)
The only boring thing is that I have to mod every control (FieldControl, NumberControl, etc.), that I use in my app... Sometimes I'm so lazy! :P
 
 
Mauro
 
#121
Re:Intercept 'enter' key in a control 4 Years, 5 Months ago
You could probably override FieldControl in your application and add this. Then everything that derived from FieldControl would get it.

Of course, then you would get it in dialogs where you might not want it :-(
 
 
andrew
 
#122
Re:Intercept 'enter' key in a control 4 Years, 5 Months ago
I have successfully overrided the FieldControl but I don't know why the enter key check is not working when I use a ChooseListControl that is supposed to create a field control... :(
 
 
Mauro
 
#123
Re:Intercept 'enter' key in a control 4 Years, 5 Months ago
Some controls already define GETDLGCODE and CHAR so they will override the Field changes. ChooseListControl inherits this from ChooseControl.

So you're back to modifying multiple controls, unfortunately.
 
 
andrew
 
#124
Re:Intercept 'enter' key in a control 4 Years, 5 Months ago
Fortunately I have just started my new app so I will just make me few of my custom controls and use them where this kind of behaviour is needed.
 
 
#126
Re:Intercept 'enter' key in a control 4 Years, 5 Months ago
andrew wrote:
Some controls already define GETDLGCODE and CHAR so they will override the Field changes. ChooseListControl inherits this from ChooseControl.In the Fieldproc method, ChooseControl catches the messages from the Field that it creates, then I have had to modify it in this way:

Code:


Fieldproc(hwnd, msg, wparam, lparam)
{
if (msg is WM.GETDLGCODE)
return .FieldProc_DlgCode(hwnd, msg, wparam, lparam)
if  .FieldProc_DropDown?(hwnd, msg, wparam, lparam)
{
.On_DropDown();
return 0;
}
if (msg is WM.SYSCHAR and .Alt_z?(wparam, lparam))
return 0

if (msg is WM.SETFOCUS)
.FieldSetFocus()
if (msg is WM.KILLFOCUS)
.FieldKillFocus()
if (msg is WM.CHAR and wparam is VK.TAB)
return 0
if (msg is WM.CHAR and wparam is VK.RETURN)
{
.FieldReturn()
SetFocus(GetNextDlgTabItem(.Window.Hwnd, hwnd, false)) //*** LINE ADDED!
return 0
}

return CallWindowProc(.prevproc, hwnd, msg, wparam, lparam);
}


With this mod, the enter key works in the DateControl too!
I have overriden the NumberControl, the EuroNumberControl, the PatternControl, the FieldControl and the ChooseControl and for now the enter key works in every control of my interface. :)

Post edited by: Mauro, at: 2006/03/21 21:37
 
 
Mauro