Page 1 of 2

Posted: Wed Apr 10, 2002 11:01 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

Code: Select all

; Example of how to make Return act as Tab to switch gadget focus.
; By PB -- feel free to use any way you wish.  :)
;
GetAsyncKeyState_(#VK_RETURN) ; To flush buffer of Return key.
;
If OpenWindow(0,100,150,450,200,#PB_Window_SystemMenu,"Test")
  CreateGadgetList(WindowID())
  ; Flags for StringGadget stop the "ding" sound when pressing Enter.
  StringGadget(1,50,50,350,20,"",#PB_String_Multiline|#ES_AUTOVSCROLL)
  ButtonGadget(2,200,100,50,25,"Test")
  ActivateGadget(1) ; Give StringGadget the focus at startup.
  Repeat
    ev=WaitWindowEvent() : id=EventGadgetID()
    Select ev
      Case #PB_EventGadget
        If id=2 : MessageRequester("Button","Hi there!",0) : EndIf
      Default ; Hopefully this becomes #PB_EventKey in a future PureBasic... :wink:
        If GetAsyncKeyState_(#VK_RETURN)=-32767 ; Return key was pressed!
          keybd_event_(#VK_RETURN,0,#KEYEVENTF_KEYUP,0) ; Force Return key up.
          keybd_event_(#VK_TAB,0,0,0) ; TAB key down.
          keybd_event_(#VK_TAB,0,#KEYEVENTF_KEYUP,0) ; TAB key up.
        EndIf        
    EndSelect
  Until ev=#PB_EventCloseWindow
EndIf

Posted: Thu Apr 11, 2002 7:27 am
by BackupUser
Restored from previous forum. Originally posted by Rings.

thx.nice snippet.

Its a long way to the top if you wanna .....CodeGuru

Posted: Thu Apr 11, 2002 10:02 am
by BackupUser
Restored from previous forum. Originally posted by Manolo.

Thanks PB. This solve my problem.

Manolo

Posted: Thu Apr 11, 2002 4:12 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.

Thanks PB,

Because of this snippet I was able to get rid of:
InitSprite()
InitKeyboard()
ExamineKeyboard()
And with that a lot of unused KB.

Thanks again, it's truly appreciated


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.

Posted: Thu Apr 11, 2002 9:39 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
Because of this snippet I was able to get rid of:
InitSprite()
InitKeyboard()
ExamineKeyboard()
And with that a lot of unused KB.
That's why I like using the Windows API when programming: it saves a bucketload
of code and custom-written routines. Glad I could help you all!


PB - Registered PureBasic Coder

Revisiting an Old Topic

Posted: Mon Oct 22, 2007 9:58 pm
by Slyvnr
I know this is an old topic. I have seen several examples in forums about capturing the Return key to make it act like a Tab Key or to "Press" a button in your window.

My question is why is it that I have to create code for such a basic function as these.

A Return key when pressed on a data entry type gadget (StringGadget, CheckBox, ComboBox, etc) should automatically act like a tab key.

A Return key when pressed on an action type gadget (ButtonGadget) should automatically act like a LeftMouseButton press.

This is standard behavior for all programs in a WYSIWYG type interface.

I bring this up because all of the sample workarounds are great for Windows but because they use Windows API calls are useless when the program needs to support this activity on Mac and Linux based systems.

The question I now propose is this:

Is there a way, without using the windows API, to make a Return Key act like a Return Key (as described above) ?

I have tried many different methods to "Capture" the keyinput/keypress with InitSprite, OpenWindowScreened, ExamineKeyboard, etc. but do not get the needed results, get partial results I.e. act like a tab, but not "Press" a button. This is also a LOT of waste code in my opinion.

Thanks for the input


Slyvnr

Re: Revisiting an Old Topic

Posted: Mon Oct 22, 2007 11:55 pm
by PB
> A Return key when pressed on a data entry type gadget (StringGadget,
> CheckBox, ComboBox, etc) should automatically act like a tab key.
> This is standard behavior for all programs in a WYSIWYG type interface.

I've never seen this as a standard behaviour in any app that I've used.

Behaviour

Posted: Tue Oct 23, 2007 12:21 am
by Slyvnr
Quicken it either acts as a Tab or as a "Save" or "OK" type action depending on what type of data entry is being done.

Peachtree - usually acts as tab. Some cases acts as the "Save"

Proseries (tax software by Intuit) - usually acts as a "Save" or "OK"

Act! - usually acts as a tab

Access programs tends to act like the highlighted button ("default action")

TurboCad - depends on what you are doing...mostly acts like Tab...several areas acts like a "Save & Close Dialog box"...inconsistent which drives me crazy because I am use to using it as tab to next field and not save and close...usually hit it when I needed a tab and have to reopen dialog box.

Slyvnr

Posted: Tue Oct 23, 2007 1:05 am
by rsts
Not that it might not be nice, but a few programs where it 'tends to' or 'usually acts' or 'depends on' does not sound like 'standard behavior for all programs in a WYSIWYG type interface' to me.

Is there some more official source of this 'standardization' you're aware of?

cheers

Re: Behaviour

Posted: Tue Oct 23, 2007 1:47 am
by PB
> Quicken it either acts as a Tab or as a "Save" or "OK" type action

So there's no actual standard behavior then.

> Peachtree - usually acts as tab. Some cases acts as the "Save"

So there's no actual standard behavior then.

> Proseries (tax software by Intuit) - usually acts as a "Save" or "OK"

So there's no actual standard behavior then.

> Act! - usually acts as a tab

So there's no actual standard behavior then.

> TurboCad - depends on what you are doing

So there's no actual standard behavior then.

:?

I agree with rsts. What you've shown is a small selection of proprietary
apps that make the Enter key do what they want, depending on what
the user is doing at the time. This does mean it's standard behavior in
all Windows apps. In fact, all the apps you've mentioned above are not
even what one would class as "everyday apps for everyday users".
They are mostly just specialized tools for financial markets.

Standards

Posted: Tue Oct 23, 2007 1:45 pm
by Slyvnr
In fact, all the apps you've mentioned above are not
even what one would class as "everyday apps for everyday users".
The applications not meant for the everyday user? In fact, Quicken is meant for the everyday user and has a very large user base (over 15 million). Act! is the #1 contact management systems in the world with a user base of 2.7 million users (41,000 corporate clients). Peachtree is generic accounting software with a user base in excess of 2.5 million. I did not mention Goldmine (another contact manager) or Money (a quicken take-off) because I do not have experience with them.

When making a "commercial ready" application, these are the type of applications that must be compared against if attempting to do a "Commercial" Package in Purebasic. (Which according to online discussion is possible, but I have yet to find a "Large Install Base of any Purebasic commercial applications").

Don't get me wrong, I like Purebasic, but I am still unsure if it truly can meet the needs of large commercial developers. I am in the process of designing and developing an application meant to service a large commercial user base, and am still trying to determine the development environment that will make such project 1) easy to develop in, 2) easy to maintain long term, 3) create small executables vs. Bloat-ware along with numerous other objectives.

When I have to make workarounds for some basic functionality of making the Return key work, instead of turning it down or giving it a negative mark I question it. I researched the Forums (no complete help, some band aid solutions) and then I post the query for others to respond to.

Other Applications that have default actions for enter. Excel spreadsheet, enter key pressed stores cell contents and moves to next field. (Same in OpenOffice Spreadsheet). If you use the keyboard for moving through menus, the enter key activates the menu item highlighted.

I guess the standard is a two edged sword in that it depends on if a Default Button/Action is defined or not. Instead of getting into arguments over schematics let me rephrase this.

Most applications tend to have the enter key default to some action (usually Tab or Activate if a default button is always highlighted)

In psuedo-code it would be

Code: Select all

If "Enter/Return" Key pressed and No Default Button/Action Defined/ Highlighted
    Act like Tab key
Elseif "Enter/Return" Key pressed and Default Button/Action Defined/Highlighted 
    Activate Default Button/Action
Endif
Versus in Purebasic we have default actions for the likes of "#PB_Shortcut_Tab" and "#PB_Shortcut_ShiftTab" at all times, but do not have "#PB_Shortcut_Return".

While defining #PB_Shortcut_Return using the AddshortcutKey allows for the enter key to act like tab you can not generically define it to check for the Gadgettype (i.e. Data Entry Gadget vs. Activation Gadget) so that it can activate the button if on a highlighted button. With a ton of excess code could probably put a check on each Gadget to see if active and if "Enter" pressed, but this adds a lot of, what I feel, is unnecessary coding. Could probably make it into a generic procedure so that the amount of code is reduced, but this is still quite inefficient. (Coming from old Dbase/Clipper/Foxbase/FoxPro programming where this type of coding was unnecessary..I mean we are not programming in C/C++ here).

All of the solutions that I have found in the forums for making the Return key to act like a "Enter" key (i.e. activate a button if it is highlighted) rely on Windows API_ and therefore the application is not cross-platform compatible.

The question once again, is there a way to accomplish this with out relying on the Windows API_? The application will be a data-intensive entry system and the functionality of the enter key for speed is crucial.

Thanks

Slyvnr

Posted: Tue Oct 23, 2007 2:23 pm
by maw
Quite easily actually. You first do a AddKeyboardShortcut for #PB_Shortcut_Return, then in your main loop whenever you get an EventMenu for that shortcut you check which gadget is the active gadget and then activate the next gadget. This would be easiest if you simply have a list of the gadgets in the correct tab order and simply look up the current gadget and retrieve the next list item which would then be the next gadget to activate.

And I have to say that in an application where you are supposed to input alot of data, having enter working the correct way is cruicial.

EventMenu

Posted: Tue Oct 23, 2007 2:43 pm
by Slyvnr
Ok, So I check for EventMenu and then compare to a list of "Active" Gadgets. If it falls within the Active Gadgets list, then Activate, if not Active Gadget then act like tab.

And this should thus get rid of the need for using the Keyboard Input keywords under InitSprite, OpenWindowedScreen(), ExaminKeyBoard, KeyboardInKey() etc.

Will attempt this. Thanks for the input.

Are there other more efficient ways?

Slyvnr

Posted: Tue Oct 23, 2007 7:09 pm
by srod
This is the best way slyvnr; very simple and totally at your control.

I nearly mentioned this before but reckoned I must have misunderstood what it is you were after because it seemed so clear cut to me.

Personally I wouldn't want such 'behaviour' set in stone and would rather things be left to the programmer.

Posted: Wed Oct 24, 2007 5:57 am
by electrochrisso
I made a couple of changes to the above code.

1. Converted it to PB 4
2. Added another String Gadget.
3. Added Backspace key up/down to get rid of the return character in string gadgets to keep characters visible for forms etc.

I hope you don't mind :wink:

Code: Select all

; Example of how to make Return act as Tab to switch gadget focus.
; By PB -- feel free to use any way you wish.
;
GetAsyncKeyState_(#VK_RETURN) ; To flush buffer of Return key.
;
If OpenWindow(0,100,150,450,200,"Test",#PB_Window_SystemMenu)
  CreateGadgetList(WindowID(0))
  ; Flags for StringGadget stop the "ding" sound when pressing Enter.
  StringGadget(1,50,50,150,20,"",#ES_MULTILINE|#ES_AUTOVSCROLL)
  StringGadget(2,250,50,150,20,"",#ES_MULTILINE|#ES_AUTOVSCROLL)
  ButtonGadget(3,200,100,50,25,"Test")
  SetActiveGadget(1) ; Give StringGadget the focus at startup.
  Repeat
    ev=WaitWindowEvent() : id=EventGadget()
    Select ev
      Case #PB_Event_Gadget
        If id=3 : MessageRequester("Button","Hi there!",0) : EndIf
      Default ; Hopefully this becomes #PB_EventKey in a future PureBasic...
        If GetAsyncKeyState_(#VK_RETURN)=-32767 ; Return key was pressed!
          keybd_event_(#VK_RETURN,0,#KEYEVENTF_KEYUP,0) ; Force Return key up.
          keybd_event_(#VK_BACK,0,0,0) ; Backspace key down.
          keybd_event_(#VK_BACK,0,#KEYEVENTF_KEYUP,0) ; Backspace key up.
          keybd_event_(#VK_TAB,0,0,0) ; TAB key down.
          keybd_event_(#VK_TAB,0,#KEYEVENTF_KEYUP,0) ; TAB key up.
        EndIf        
    EndSelect
  Until ev=#PB_Event_CloseWindow
EndIf