1. win32lib pronlem
- Posted by ChrisB (moderator) 2 weeks ago
- 305 views
Hi
Win32lib
Simple dialogue with editText entry, an ok and a cancel button.
How do i simulate a click of the ok button when I hit enter when entering text?
procedure EditText19_onKeyUp (integer self, integer event, sequence params)--params is ( int scanCode, int shift ) if params[1] = VK_RETURN then puts(1, "PushButton20 clicked \n") -- it does trigger when Enter is pressed setFocus(PushButton20) -- makes no difference sendMessage(PushButton20, w32HClick, 0, 0) end if end procedure setHandler( EditText19, w32HKeyUp, routine_id("EditText19_onKeyUp"))
TIA Chris
2. Re: win32lib pronlem
- Posted by ghaberek (admin) 2 weeks ago
- 294 views
The proper solution for making a dialog is to use DefPushButton (and CancelButton) instead of PushButton. They will intercept the Enter and Escape key events automatically. You just need to set your w32HClick handler.
DefPushButton
Default command button control.
A DefPushButton is a PushButton, but is displayed with an extra border indicating that this button will automatically be selected if the user presses the Return button on the keyboard.
CancelButton
Command button that reacts to the Escape key.
A CancelButton is a PushButton, but is displayed with italic font indicating that this button will automatically be selected if the user presses the Escape key.
You can use registerHotKey() to associate a key code (e.g. VK_ESCAPE) to a control. I know its description says "ALT-key combination" but that's left over from when it was only for applying mnemonics (e.g. "&New" -> "New").
registerHotKey ( integer id, object caption )
Allows you to associate a ALT-key combination to set focus to a control.
Any control or Window can have any number of hotkeys registered.
id is the control/window id returned by create()
caption is either a single keycode, or a string containing a '&' character.
If using a keycode, you must use the keycode names in w32Keys.e. If using a string, the uppercase version of the character following the '&' is used. Note that this is happens automatically when you create() a control with some caption text. Also, the default pushbutton, if any, is automatically registered with VK_RETURN.
If you want to handle this manually, use w32HKeyDown instead of w32HKeyUp. Typically "click" events are triggered on mouse up and key down. Then use invokeHandler() to trigger w32HClick instead of sendMessage().
w32HKeyDown
Key is pressed.
parms = {integer keyCode, integer shift}
The keyCode is "raw" value of the key. The primary purpose of onKeyDown is to trap "special" keys not reported by onKeyPress.
invokeHandler ( integer id, integer event, sequence params)
Triggers a Win32Lib event.
Returns: OBJECT: The value set by returnValue() if called inside
-Greg
3. Re: win32lib pronlem
- Posted by ChrisB (moderator) 2 weeks ago
- 270 views
Perfect, thanks, great signposting for the other options.
invokeHandler was all I needed,
Cheers
Chris