FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Detect ESC on dialog
Posts: 104
Joined: Tue Feb 09, 2021 04:20 PM
Detect ESC on dialog
Posted: Mon Mar 10, 2025 07:19 PM
try this:
   ::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 ?

José M. C. Quintas Brazil

gtwvg, fivewin 25.12, hwgui, mingw 15.2 (32 bits)

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Detect ESC on dialog
Posted: Mon Mar 10, 2025 08:14 PM
Dear José,

SetDialogEsc( .F. ) should allow you to handle it, but it is not. We have to review it:
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
Re: Detect ESC on dialog
Posted: Tue Mar 11, 2025 04:37 AM
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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Detect ESC on dialog
Posted: Tue Mar 11, 2025 06:42 AM
Dear Ramesh,

Many thanks for you feedback :)

Is the above example working fine for you ? Do you get the VK_ESCAPE MsgInfo() ?

best regards
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Detect ESC on dialog
Posted: 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?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Detect ESC on dialog
Posted: Tue Mar 11, 2025 10:18 AM
Silvio.Falconi wrote: 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Detect ESC on dialog
Posted: Tue Mar 11, 2025 10:27 AM
Antonio Linares wrote:
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
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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
Re: Detect ESC on dialog
Posted: Wed Mar 12, 2025 03:42 AM
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
Posts: 104
Joined: Tue Feb 09, 2021 04:20 PM
Re: Detect ESC on dialog
Posted: Wed Mar 12, 2025 01:10 PM

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 ?

José M. C. Quintas Brazil

gtwvg, fivewin 25.12, hwgui, mingw 15.2 (32 bits)

Posts: 104
Joined: Tue Feb 09, 2021 04:20 PM
Re: Detect ESC on dialog
Posted: Wed Mar 12, 2025 01:36 PM
On this class, NOT DIALOG, I use this:
   VAR lHitESC    INIT .F.
I use like Inkey(), to end process first
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.

José M. C. Quintas Brazil

gtwvg, fivewin 25.12, hwgui, mingw 15.2 (32 bits)

Posts: 104
Joined: Tue Feb 09, 2021 04:20 PM
Re: Detect ESC on dialog
Posted: Wed Mar 12, 2025 02:05 PM
Not sure if can be interesting or not:

On VB6 there exists the KeyPress(), anything like bKeyDown.
It works like harbour INKEY_FILTER.
function KeyPress( KeyAscii )
   IF KeyAscii = ESC
      KeyAscii = 0
    ENDIF
    RETURN
equivalent fivewin:
dialog:bKeyDown := { | nkey | routine( @nKey ), nKey }
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

José M. C. Quintas Brazil

gtwvg, fivewin 25.12, hwgui, mingw 15.2 (32 bits)

Posts: 104
Joined: Tue Feb 09, 2021 04:20 PM
Re: Detect ESC on dialog
Posted: Wed Mar 12, 2025 02:37 PM
From an older fivewin user: GetKeyState()
   ::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.

José M. C. Quintas Brazil

gtwvg, fivewin 25.12, hwgui, mingw 15.2 (32 bits)

Continue the discussion