Detect ESC on dialog

Post Reply
JoséQuintas
Posts: 74
Joined: Tue Feb 09, 2021 4:20 pm
Been thanked: 1 time

Detect ESC on dialog

Post 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 ?
José M. C. Quintas Brazil
gtwvg, fivewin 25.01, hwgui, mingw 15.0 rc (32 bits)
User avatar
Antonio Linares
Site Admin
Posts: 42651
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 94 times
Contact:

Re: Detect ESC on dialog

Post 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  
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
RAMESHBABU
Posts: 632
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India
Been thanked: 5 times

Re: Detect ESC on dialog

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 42651
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 94 times
Contact:

Re: Detect ESC on dialog

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Silvio.Falconi
Posts: 7187
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 9 times

Re: Detect ESC on dialog

Post 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?
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
User avatar
Antonio Linares
Site Admin
Posts: 42651
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 94 times
Contact:

Re: Detect ESC on dialog

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Silvio.Falconi
Posts: 7187
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 9 times

Re: Detect ESC on dialog

Post 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
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
User avatar
RAMESHBABU
Posts: 632
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India
Been thanked: 5 times

Re: Detect ESC on dialog

Post 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
JoséQuintas
Posts: 74
Joined: Tue Feb 09, 2021 4:20 pm
Been thanked: 1 time

Re: Detect ESC on dialog

Post 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 ?
José M. C. Quintas Brazil
gtwvg, fivewin 25.01, hwgui, mingw 15.0 rc (32 bits)
JoséQuintas
Posts: 74
Joined: Tue Feb 09, 2021 4:20 pm
Been thanked: 1 time

Re: Detect ESC on dialog

Post by JoséQuintas »

On this class, NOT DIALOG, I use this:

Code: Select all | Expand

   VAR lHitESC    INIT .F.
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.
José M. C. Quintas Brazil
gtwvg, fivewin 25.01, hwgui, mingw 15.0 rc (32 bits)
JoséQuintas
Posts: 74
Joined: Tue Feb 09, 2021 4:20 pm
Been thanked: 1 time

Re: Detect ESC on dialog

Post 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:

Code: Select all | Expand

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.01, hwgui, mingw 15.0 rc (32 bits)
JoséQuintas
Posts: 74
Joined: Tue Feb 09, 2021 4:20 pm
Been thanked: 1 time

Re: Detect ESC on dialog

Post 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.
José M. C. Quintas Brazil
gtwvg, fivewin 25.01, hwgui, mingw 15.0 rc (32 bits)
Post Reply