bKeyDown and interactive "close"

bKeyDown and interactive "close"

Postby Jimmy » Thu Nov 17, 2022 9: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: Select all  Expand view
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
User avatar
Jimmy
 
Posts: 1590
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: bKeyDown and interactive "close"

Postby Antonio Linares » Thu Nov 17, 2022 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41405
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: bKeyDown and interactive "close"

Postby Jimmy » Thu Nov 17, 2022 10:52 am

hi Antonio,

i have made a small Sample
Code: Select all  Expand view
#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
User avatar
Jimmy
 
Posts: 1590
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: bKeyDown and interactive "close"

Postby cnavarro » Thu Nov 17, 2022 12:59 pm

Change,
Code: Select all  Expand view

oWnd:bKeyDown := { | nKey, nFlag | ...
 

by
Code: Select all  Expand view

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
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: bKeyDown and interactive "close"

Postby Enrico Maria Giordano » Thu Nov 17, 2022 6:19 pm

DEFAULT clause seems to work fine with DIALOG but not with WINDOW:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8378
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: bKeyDown and interactive "close"

Postby Jimmy » Fri Nov 18, 2022 7: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: Select all  Expand view
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
User avatar
Jimmy
 
Posts: 1590
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: bKeyDown and interactive "close"

Postby nageswaragunupudi » Fri Nov 18, 2022 9: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
User avatar
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: bKeyDown and interactive "close"

Postby Jimmy » Fri Nov 18, 2022 10:33 am

hi,

found Solution :D

Code: Select all  Expand view
{ | 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
User avatar
Jimmy
 
Posts: 1590
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: bKeyDown and interactive "close"

Postby Antonio Linares » Fri Nov 18, 2022 10:47 am

Very good! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41405
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests