Well, times has changed and the keyboard is only one of many devices, you don´t have one type of input fields but different kinds (Textbox, Editbox, Datepicker, ...).
Here is my solution to do something like the old keyboard() command. My wish was to insert the actual date at the current cursor position by pressing the F2 key when the user is in a form. In Textbox and Editbox the date should be inserted, in Datepicker the existing value should be replaced. If the cursor (or focus) is on another control, nothing should be happen.
First we define a form with the three kinds of controls:
Code: Select all
#include "hmg.ch"
#include "hbqtgui.ch"
FUNCTION Main()
LOCAL oForm1
HbQt_ErrorSys()
DEFINE MAINWINDOW oForm1
ROW 10
COL 10
WIDTH 300
HEIGHT 200
FONT "ARIAL"; SIZE 09
DEFINE TEXTBOX oTextBox1
ROW 10; COL 10
WIDTH 200; HEIGHT 20
VALUE "Press F2 "
END TEXTBOX
DEFINE EDITBOX oEditBox1
ROW 40; COL 10
WIDTH 200; HEIGHT 100
VALUE " and here too"
END EDITBOX
DEFINE DATEPICKER oDatePick1
ROW 160; COL 10
WIDTH 90; HEIGHT 20
VALUE CTOD("01/01/2010")
END DATEPICKER
END Window
ACTIVATE WINDOW oForm1
RETURN Nil
Code: Select all
...
END Window
ON KEY F2 of oForm1 action InsertDate( )
ACTIVATE WINDOW oForm1
....
Code: Select all
oWidget := HMGAPP():ThisW()
Code: Select all
cClassname := oWidget:QTObject:className()
The whole function would look like:
Code: Select all
FUNCTION InsertDate( )
LOCAL oWidget := HMGAPP():ThisW()
LOCAL cClassname
IF hb_IsObject( oWidget )
cClassname := oWidget:QTObject:className()
DO CASE
CASE cClassname == "QLINEEDIT"
oWidget:QTObject:insert( DTOC( DATE() ) )
CASE cClassname == "QTEXTEDIT"
oWidget:QTObject:insertPlainText( DTOC( DATE() ) )
CASE cClassname == "QDATEEDIT"
oWidget:QTObject:setDate( QDate( YEAR( DATE() ), MONTH( DATE() ), DAY( DATE() ) ) )
ENDCASE
ENDIF
RETURN Nil
Ricci