FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour bKeyDown and interactive "close"
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
bKeyDown and interactive "close"
Posted: Thu Nov 17, 2022 09:05 AM
hi,

i have a GET and a BUTTON in oWnd
now i want to use VK_RETURN for ACTION and close oWnd
Code (fw): Select all Collapse
PROCEDURE MakeNewFolder()
LOCAL cSourceDir := IF( nGridFocus = 1, cExpl_Left:oGrid:cPath, cExpl_Right:oGrid:cPath )
LOCAL cPath      := SPACE( 100 )
LOCAL oWnd, oLabel_1, oText_1, oBtn, oTimer

   DEFINE WINDOW oWnd FROM 0, 0 TO 180, 500 PIXEL TITLE "Create New Folder" ICON "A1MAIN" NOMINIMIZE NOMAXIMIZE

      @ 010, 010 SAY oLabel_1 PROMPT cSourceDir SIZE 460, 30 PIXEL FONT oFontDefault OF oWnd         
      @ 040, 010 GET oText_1 VAR cPath SIZE 460, 30 PIXEL FONT oFontDefault OF oWnd                  

      @ 080, 010 BUTTON oBtn PROMPT "&OK" SIZE 460, 50 PIXEL FONT oFontDefault ACTION DoCreateFolder( cSourceDir, cPath ) OF oWnd

      oWnd:bKeyDown := { | nKey, nFlag | IF( nKey = VK_ESCAPE, oWnd:End(), IF( nKey = VK_RETURN, ( DoCreateFolder( cSourceDir, cPath ), oWnd:End() ), nil ) ) }
      oWnd:bResized := { | nType, nWidth, nHeight | oWnd:SetSize( 500, 180 ) }

      DEFINE TIMER oTimer INTERVAL 100 ACTION( SnapToCtrl( oWnd, oBtn, oTimer ), oTimer:End() ) OF oWnd
      ACTIVATE TIMER oTimer

#IFDEF __HMG__
   END WINDOW
#ENDIF

   oText_1:Setfocus()
   ACTIVATE WINDOW oWnd ON INIT MakeTop( oWnd ) CENTER

  oTimer:End()
RETURN
ESC seem to work but ENTER goes to BUTTON ... hm

---

when have type into GET and press "close" Button (upper - right) i expect "nothing" happens
but it "does" do DoCreateFolder() ... :shock: ...hm

have no Idea what is going on

did someone have a Sample how to use ENTER of GET to activate ACTION of "Ok" Button
need some help please
greeting,

Jimmy
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: bKeyDown and interactive "close"
Posted: Thu Nov 17, 2022 09:13 AM

Dear Jimmy,

Simply add clause DEFAULT to the button:

@ 080, 010 BUTTON oBtn PROMPT "&OK" SIZE 460, 50 PIXEL FONT oFontDefault ACTION DoCreateFolder( cSourceDir, cPath ) OF oWnd DEFAULT

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: bKeyDown and interactive "close"
Posted: Thu Nov 17, 2022 10:52 AM
hi Antonio,

i have made a small Sample
Code (fw): Select all Collapse
#include "FiveWin.ch"

PROCEDURE Main()
LOCAL cSourceDir := hb_dirbase()
LOCAL cPath      := SPACE( 100 )
LOCAL oWnd, oLabel_1, oText_1, oBtn

   DEFINE WINDOW oWnd FROM 0, 0 TO 180, 300 PIXEL TITLE "Create New Folder" NOMINIMIZE NOMAXIMIZE

      @ 010, 010 SAY oLabel_1 PROMPT cSourceDir SIZE 260, 30 PIXEL OF oWnd
      @ 040, 010 GET oText_1 VAR cPath SIZE 260, 30 PIXEL OF oWnd

      @ 080, 010 BUTTON oBtn PROMPT "&OK" SIZE 260, 50 PIXEL ACTION( DoCreateFolder( cSourceDir, cPath ), oWnd:End() ) OF oWnd DEFAULT

#IFDEF __HMG__
   END WINDOW
#ENDIF

   oWnd:bKeyDown := { | nKey, nFlag | IF( nKey = VK_RETURN,;
                     ( DoCreateFolder( cSourceDir, cPath ), oWnd:End() ) ,;
                     IF( nKey = VK_ESCAPE, oWnd:End(), nil ) ) }

   oWnd:bResized := { | nType, nWidth, nHeight | oWnd:SetSize( 300, 180 ) }

   ACTIVATE WINDOW oWnd CENTER

RETURN

STATIC PROCEDURE DoCreateFolder( cSourceDir, cPath, oWnd )
   MsgInfo(TRIM(cSourceDir + cPath))
RETURN
i like to type in GET and than press ENTER
you will see MsgInfo() appear but NO cPath from GET :?:

when press BUTTON than it is ok.
what i´m doing wrong :?:
greeting,

Jimmy
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: bKeyDown and interactive "close"
Posted: Thu Nov 17, 2022 12:59 PM
Change,
Code (fw): Select all Collapse
oWnd:bKeyDown := { | nKey, nFlag | ...
by
Code (fw): Select all Collapse
oText_1:bKeyDown := { | nKey, nFlag | ...
and try
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: bKeyDown and interactive "close"
Posted: Thu Nov 17, 2022 06:19 PM
DEFAULT clause seems to work fine with DIALOG but not with WINDOW:
Code (fw): Select all Collapse
#include "FiveWin.ch"

PROCEDURE Main()
LOCAL cSourceDir := hb_dirbase()
LOCAL cPath      := SPACE( 100 )
LOCAL oDlg

   DEFINE DIALOG oDlg TITLE "Create New Folder" SIZE 800, 600

      @ 010, 010 SAY cSourceDir SIZE 260, 30 PIXEL OF oDlg
      @ 040, 010 GET cPath SIZE 260, 30 PIXEL OF oDlg

      @ 080, 010 BUTTON "&OK" SIZE 260, 50 PIXEL ACTION( DoCreateFolder( cSourceDir, cPath ), oDlg:End() ) OF oDlg DEFAULT

#IFDEF __HMG__
   END WINDOW
#ENDIF

   ACTIVATE DIALOG oDlg CENTER

RETURN

STATIC PROCEDURE DoCreateFolder( cSourceDir, cPath )
   MsgInfo(TRIM(cSourceDir + cPath))
RETURN
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: bKeyDown and interactive "close"
Posted: Fri Nov 18, 2022 07:46 AM
hi,

i have make more test and it is always GET where i have the Problem

when have e.g. a LISTBOX i does work with bKeydown an ENTER (VK_RETURN)
also VK_ESCAPE does work to "close" Window at all Controls

---

when have many GET i can use ENTER, instead of TAB, to "jump" to next GET
Code (fw): Select all Collapse
2154      case nKey == VK_TAB .or. nKey == VK_RETURN
so ENTER is "internal" used by GET and CODEBLOCK will not get nKey = 13
greeting,

Jimmy
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: bKeyDown and interactive "close"
Posted: Fri Nov 18, 2022 09:39 AM

Use bKeyDown.

You can handle VK_RETURN and if you handle VK_KEYDOWN in your codeblock, return 0 else return NIL.

Regards



G. N. Rao.

Hyderabad, India
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: bKeyDown and interactive "close"
Posted: Fri Nov 18, 2022 10:33 AM
hi,

found Solution :D
Code (fw): Select all Collapse
 { | nKey, nFlag | IF( nKey = VK_RETURN,;
  ( Syswait(0.1),DoCreateFolder( cSourceDir, cPath ), oWnd:End() ) ,;
  IF( nKey = VK_ESCAPE, oWnd:End(), nil ) ) }
i have used MsgInfo() before and cPath was empty() :(
but after close MsgInfo() i got next MsgInfo() with Result and that was ok ... :? ... hm

so i use Syswait(0.1) before call Function and that work
greeting,

Jimmy
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: bKeyDown and interactive "close"
Posted: Fri Nov 18, 2022 10:47 AM
Very good! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion