PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Catch ENTER key on controls  (Read 134 times)

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 445
Catch ENTER key on controls
« on: December 08, 2019, 01:02:15 PM »

Good Day

How do i catch an ENTER key on a Textbox and Buttons that usually don't support it?

I have users that say its faster in typing if they just type and Enter instead of my approach of Tab on text boxes and Space key on buttons.
My Keydown events attempts had caused some undesirable and interesting outcomes.
 :)

(This is still in Powerbasic)

Regards, PEter
Logged

Ian Vincent

  • Little Newbie
  • *
  • Posts: 27
  • FF3 User
Re: Catch ENTER key on controls
« Reply #1 on: December 08, 2019, 09:43:32 PM »

Petrus,

One way is to put this in the KeyUp section:

'*****Put in the KeyUp event ************
Local aa As String
If nVirtKey=13 Then
    aa=FF_Control_GetText( hWndControl)
    'do what you want with aa
    FF_Control_SetFocus( HWND_RECORDING_TEXT2 )
End If

(there might be better ways)

Ian
Logged

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 445
Re: Catch ENTER key on controls
« Reply #2 on: December 09, 2019, 11:34:16 AM »

Thanks Ian

I will give it a shot.
Personally i feel people must learn to use both hands when typing.

There are some that still comes from the DOS days and just captures with the one hand.

Regards,

Peter
Logged

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 445
Re: Catch ENTER key on controls
« Reply #3 on: December 09, 2019, 11:40:06 AM »

Thanks Ian

went this way:

Code: [Select]
Select Case nVirtkey

Case 13   
     
  FF_Control_SetFocus(HWND_FORM3_TEXT5)

End Select

Works, perfectly, Thanks!

-Peter
Logged

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 445
Re: Catch ENTER key on controls
« Reply #4 on: December 09, 2019, 11:58:21 AM »

Controls that does NOT have a key-up event ( I have a firetextbox still in use for the currency control) or a Image button...
How do i go that route?

Sorry for all the questions, I never anticipated a request like that for enter keys.

-Peter
Logged

Klaas Holland

  • Junior Member
  • **
  • Posts: 106
  • FF3 User
Re: Catch ENTER key on controls
« Reply #5 on: December 10, 2019, 08:54:42 AM »

When you want the Enter-Key to act as the Tab-Key, you change the Pumphook to:

For FF-PowerBasic the code is:

'----------------------------------------------------------------------------------------------------
Function FF_PUMPHOOK( Msg As tagMsg ) As Long


   ' If this function returns FALSE (zero) then the processing of the regular
   ' FireFly message pump will continue. Returning TRUE (non-zero) will bypass the regular message pump.

   Function = %FALSE    'return %TRUE if you need to bypass the FireFly message pump

   ' If you are dealing with a 'normal' OCX control then the following code will
   ' allow the message to be forwarded to the OCX.
   #If %USEOLECON = 1
      Function = OC_ForwardMessage( GetFocus(), Msg)
   #EndIf

'    Filter the ENTER key For the command buttons
   Select Case Msg.Message
     
      Case %WM_KEYDOWN
         Local hFocus    As Dword
         Local idControl As Long 
         
         hFocus      = GetFocus()
         
         If Msg.wParam = %VK_RETURN Then
            ' Only handle the ENTER key for the CommandButtons that we are interested in.
            Static zClass As Asciiz * 50
            GetClassName Msg.hWnd, zClass, SizeOf(zClass)
            If UCase$(zClass) = "BUTTON" Then

                idControl = GetWindowLong( hFocus, %GWL_ID )
                SendMessage GetParent(hFocus), %WM_COMMAND, Mak( Long, idControl, %BN_CLICKED), hFocus
                Msg.Message = %WM_NULL

            Else
                SetFocus GetNextDlgTabItem (GetActiveWindow, GetFocus, 0)

            End If   
        End If   
       
    End Select   

End Function
'----------------------------------------------------------------------------------------------------


And for FF-FreeBasic the code is:


'----------------------------------------------------------------------------------------------------
Function FF_PUMPHOOK( Msg as tagMsg ) as Long


   ' If this function returns FALSE (zero) then the processing of the regular
   ' FireFly message pump will continue. Returning TRUE (non-zero) will bypass the regular message pump.

   Function = False    'return TRUE if you need to bypass the FireFly message pump

'    Filter the ENTER key For the command buttons
   Select Case Msg.Message
     
      Case WM_KEYDOWN
         Dim hFocus    as HWnd
         Dim idControl as Long 
         
         hFocus     =  GetFocus()
         
         If Msg.wParam = VK_Return Then
            ' Only handle the ENTER key for the CommandButtons that we are interested in.
            Static zClass as ZString * 50
            GetClassName Msg.HWnd, zClass, SizeOf(zClass)
            If UCase$(zClass) = "BUTTON" Then

                idControl = GetWindowLong( hFocus, GWL_ID )
                SendMessage GetParent(hFocus), WM_COMMAND, MAKELONG(idControl, BN_CLICKED), Cast(WPARAM , hFocus)
                Msg.Message = WM_NULL

            Else
                SetFocus GetNextDlgTabItem (GetActiveWindow, GetFocus, 0)

            End If   
        End If   
       
    End Select   

End Function


'----------------------------------------------------------------------------------------------------
Logged

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 445
Re: Catch ENTER key on controls
« Reply #6 on: December 10, 2019, 01:00:54 PM »

HI Klaas!

Nice to hear from you!
PS, your company website is awesome. Very professional!!!

Thank you for this, i will go and try it immediately!!!

Regards,

Peter
Logged