Page 1 of 1
Detect ESC on dialog
Posted: Mon Mar 10, 2025 7:19 pm
by JoséQuintas
try this:
Code: Select all | Expand
::xDlg:bKeyDown := { | nKey | ;
iif( nKey == VK_ESCAPE, ::lHitEsc := .T., Nil ), ;
MsgExclamation( iif( ::lHitEsc, "ESC", "other" ) ) }
ESC do nothing, but other keys show "other"
What I can do about this ?
Re: Detect ESC on dialog
Posted: Mon Mar 10, 2025 8:14 pm
by Antonio Linares
Dear José,
SetDialogEsc( .F. ) should allow you to handle it, but it is not. We have to review it:
Code: Select all | Expand
#include "FiveWin.ch"
function Main()
local oDlg
SetDialogEsc( .F. )
DEFINE DIALOG oDlg
oDlg:bKeyDown = { | nKey | MsgInfo( "Key: " + Str( nKey ) ) }
ACTIVATE DIALOG oDlg CENTERED VALID ( ShowCallStack(), .T. )
return nil
Re: Detect ESC on dialog
Posted: Tue Mar 11, 2025 4:37 am
by RAMESHBABU
Dear Antonio,
SetDialogEsc( .F. ) should allow you to handle it, but it is not. We have to review it:
SetDialogEsc( .F. ) is working fine with me.
-Ramesh Babu P
Re: Detect ESC on dialog
Posted: Tue Mar 11, 2025 6:42 am
by Antonio Linares
Dear Ramesh,
Many thanks for you feedback
Is the above example working fine for you ? Do you get the VK_ESCAPE MsgInfo() ?
best regards
Re: Detect ESC on dialog
Posted: Tue Mar 11, 2025 10:01 am
by Silvio.Falconi
I would be interested in blocking esc or there must be a function that when a user presses ESc the procedure must check (in case of inserting/modifying records) that the user has not modified the get/combobox/radio controls etc and the procedure must tell the user "do I have to close anyway without saving?", is there a function that does this?
Re: Detect ESC on dialog
Posted: Tue Mar 11, 2025 10:18 am
by Antonio Linares
Silvio.Falconi wrote: Tue Mar 11, 2025 10:01 am
I would be interested in blocking esc or there must be a function that when a user presses ESc the procedure must check (in case of inserting/modifying records) that the user has not modified the get/combobox/radio controls etc and the procedure must tell the user "do I have to close anyway without saving?", is there a function that does this?
ACTIVATE DIALOG oDlg VALID ... // logical value
thats what VALID is implemented for
Re: Detect ESC on dialog
Posted: Tue Mar 11, 2025 10:27 am
by Silvio.Falconi
Antonio Linares wrote: Tue Mar 11, 2025 10:18 am
Silvio.Falconi wrote: Tue Mar 11, 2025 10:01 am
I would be interested in blocking esc or there must be a function that when a user presses ESc the procedure must check (in case of inserting/modifying records) that the user has not modified the get/combobox/radio controls etc and the procedure must tell the user "do I have to close anyway without saving?", is there a function that does this?
ACTIVATE DIALOG oDlg VALID ... // logical value
thats what VALID is implemented for
yes of course I have this function but sometimes not run ok
Code: Select all | Expand
VALID EXit( .f., , , oDlg )
static FUNCTION Exit( lEsc, lAsk, cMsg, oDlg )
DEFAULT lEsc := .f., lAsk := .f., cMsg := ""
if getkeystate( VK_ESCAPE )
Return( lEsc )
endif
//aGet
lAsk := DlgModified( oDlg )
// ? lAsk
If lAsk
If Empty( cMsg )
cMsg := "Do you want to exit this operation?...?"
End
If !MsgNoyes(cMsg,"Confirm Please...")
Return .f.
End
End
return .T.
static function DlgModified( oDlg )
return AScan( oDlg:aControls, { |o| o:IsKindOf( "TGET" ) .and. o:lChanged } ) > 0
If I have combobox or My Tbtnclr on dialog not run ok , it check only the get controls...sometimes
Re: Detect ESC on dialog
Posted: Wed Mar 12, 2025 3:42 am
by RAMESHBABU
Dear Antonio,
Is the above example working fine for you ? Do you get the VK_ESCAPE MsgInfo() ?
Your above example is not working as expected Enabling/Disabling Esc Key functionality.
But 'SetDialogEsc( .T. /.F.) is working fine with Resources. All my dialogs are from Resources.
That might be reason why it is working fine with me.
Regards,
-Ramesh Babu P
Re: Detect ESC on dialog
Posted: Wed Mar 12, 2025 1:10 pm
by JoséQuintas
Do not solve.
Comment about SetDialogEsc(.F.):
it changes ALL DIALOGS, may be I want to change only a specific dialog.
As example, dialog with a single browse, I want to use the ESC to exit.
Is possible to detect ESC on dialog valid ?
Re: Detect ESC on dialog
Posted: Wed Mar 12, 2025 1:36 pm
by JoséQuintas
On this class, NOT DIALOG, I use this:
I use like Inkey(), to end process first
Code: Select all | Expand
DO WHILE ! class:lHitEsc .AND. ! :eof()
:MoveNext()
ENDDO
:CloseRecordset()
IF class:lHitEsc
Dialog:Close()
ENDIF
ESC will not close dialog, but will be used to terminate process before close dialog.
Re: Detect ESC on dialog
Posted: Wed Mar 12, 2025 2:05 pm
by JoséQuintas
Not sure if can be interesting or not:
On VB6 there exists the KeyPress(), anything like bKeyDown.
It works like harbour INKEY_FILTER.
Code: Select all | Expand
function KeyPress( KeyAscii )
IF KeyAscii = ESC
KeyAscii = 0
ENDIF
RETURN
equivalent fivewin:
if fivewin uses the nKey after bkeydown, this expand possibilities, including to change the nKey value to another key.
Remembering that exists bKeyDown and bKeyChar
Re: Detect ESC on dialog
Posted: Wed Mar 12, 2025 2:37 pm
by JoséQuintas
From an older fivewin user: GetKeyState()
Code: Select all | Expand
::xDlg:bValid := { || iif( GetKeyState( VK_ESCAPE ), ::lHitEsc := .T., Nil ), ::lCanClose }
These are 2 different things.
lCanClose - if dialog can be closed
lHitEsc - if user hit ESC, this will be used by routine
This solves my current need.