Cross Platform -- Detect StringGadget Carriage Return Key

Share your advanced PureBasic knowledge/code with the community.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Cross Platform -- Detect StringGadget Carriage Return Ke

Post by netmaestro »

Here's the thing. Keyboard presses are closely related to menu commands in virtually all of the operating systems. In a windows api message pump you will see something like this:

Code: Select all

While GetMessage_(msg.MSG, #Null, #Null, #Null ) 
  TranslateMessage_(msg) 
  DispatchMessage_(msg) 
Wend 
The TranslateMessage_() function is relevant here. MSDN says:
If applications process virtual-key messages for some other purpose, they should not call TranslateMessage. For instance, an application should not call TranslateMessage if the TranslateAccelerator function returns a nonzero value. Note that the application is responsible for retrieving and dispatching input messages to the dialog box. Most applications use the main message loop for this.
And then considering this:
MSDN wrote:The TranslateAccelerator function processes accelerator keys for menu commands.
we see that keyboard presses and menu commands are closely linked in many cases and that the commonly-seen message pump I quoted is actually inadequate.

The Purebasic message loop cuts through most of the detailed OS-specific message handling and provides the PB coder with event types for each native control. What would make you happy here? What would make you stop using the term "workaround"? I'm going to guess that in this case, you would like to see something checkable in the PB event loop such as #PB_EventType_StringGadget_Return. The PB team could easily add this, it isn't beyond their reach. So let's say they do it, and you're ecstatic. But wait; what happens when the next guy says, "Hey, why doesn't the string gadget recognize the ESC key? Why do we have to use a workaround? All good languages give us this!" Then we're back to square one. By providing keyboard shortcuts (accelerators) together with stringgadget focus events, the Purebasic team has provided us with the fully cross-platform ability to respond to any key or combination in the string gadget with a very simple logic construct. Trust me, this is a good thing.

Here's what I recommend you do: Install gcc and code::blocks and write some Windows GUI's in plain C. Start very small with Static controls, buttons and work your way up to ListViews, Panels, and the like. After a month or two of seeing what it really takes to build a "beginner-level" GUI in just one operating system, you will get a sense of just how powerful and user-friendly the AddKeyboardShortcut-RemoveKeyboardShortcut pair coupled with focus events really is.

Please believe me, this is already native and you already have it.
BERESHEIT
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Cross Platform -- Detect StringGadget Carriage Return Ke

Post by Tenaja »

IdeasVacuum wrote:Do you mean the constants? http://www.purebasic.com/documentation/ ... tants.html
Exactly--that's not in the Help file. In fact, if you search the help file, you might be lucky to find a few of those constants. I copied just a few at random, and none of them showed up in the Help search. So if some newbie is reading some sample code, they won't know what the constant is, where it's defined, or how to find others like it.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Cross Platform -- Detect StringGadget Carriage Return Ke

Post by netmaestro »

Nothing secret about the constants, all you have to do is look up the help topic for AddKeyboardShortcut. They are all right there to look at.
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Cross Platform -- Detect StringGadget Carriage Return Ke

Post by RASHAD »

@NM
I liked your explanation more than anything else
Thanks
Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Cross Platform -- Detect StringGadget Carriage Return Ke

Post by IdeasVacuum »

....erm, that same list is in the in-built Help file. Contents/Reference Manual/Overview/PureBasic Constants.

Of course there are things that newbies will struggle to find and fathom. I still do, and I started programming computers when they had to be stored in cold 'orange rooms' and the output was tape or punched cards. This forum though is a goldmine of information and experts like netmaestro, Rashad, Idle, infratec, sRod and many others generously supply their help and advice to everyone. There isn't a better place for a newbie to be, not even a formal paid-for course can compete with the expert advice found here.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Cross Platform -- Detect StringGadget Carriage Return Ke

Post by Tenaja »

Well it sure would be helpful if the Search in the Help file referenced it then...

edit...
Well, the first time I copied and pasted a few into the Search, nothing came up. I "assumed" none of them would. I must have picked the only ones that wouldn't search. Since then, every one does...
That is much better than I thought.
Randy Walker
Addict
Addict
Posts: 1064
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Cross Platform -- Detect StringGadget Carriage Return Ke

Post by Randy Walker »

Tenaja wrote:It really does need a robust solution....
Thank you Tenaja. Nice to know someone is willing to acknowledge there is a void in this area of the PureBasic project.
Last edited by Randy Walker on Thu Feb 09, 2012 6:17 am, edited 1 time in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1064
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Cross Platform -- Detect StringGadget Carriage Return Ke

Post by Randy Walker »

netmaestro wrote:But wait; what happens when the next guy says, "Hey, why doesn't the string gadget recognize the ESC key? Why do we have to use a workaround? All good languages give us this!"
Too late. Beat you to it. I already *am* the next guy and already mentioned the ESC key here in this and related threads here in the forum. Its not just an issue with the Return key. Its the "Any Key" void in PureBasic, and the Return key just happens to be the most prevelent offender in my experience.
netmaestro wrote:Here's what I recommend you do: Install gcc and code::blocks and write some Windows GUI's in plain C. Start very small with...
Please believe me, this is already native and you already have it.
gcc??!! Plain C!!?? Lookie here Mr. I know I'm a dummy. I go cross-eyed looking at C and feel my brain turning to jello if I don't look away.

I recognize your workaround as what appears to be a very stable solution and already indicated my intention to adopt that workaround. My goal here now in this conversaton is to simply point out that there is a void, any workaround is still a workaround, this whole AddKeyboardShortcut input thing is a workaround and express my interest in a feasible set of commands to manage keys per say without *borrowing* or having to work around potential menu collisions just because I just want to know if a key was pressed.

Fred is a genius. Every command he designs and adds into PureBasic is there to fill a void. I think it fair to say, considering the number of commands, all the parameters and options that go with each... Fred has filled thousands of voids. Many if not most of which are a result of someone defining a void and requesing enhancements to spare them the need for workaround alternative solutions.

AddKeyboardShortcut is designed to be used in conjunction with *menu* operation and applying that design to work around an enherent void in the language is a ''workaround''. Want me to stop calling it a workaround? Fine. Get Fred to come in here and say something so I know he has at least glimped the issue. A simple ''huh?'' will do :lol:
Until then, anything else I post here only serves to keep the wheel squeaking. (Squeaky wheel gets the grease) If I know he has seen it then I know I have done all I can do. Up to him to assign significance and priority to any request so its all beyond my control at that point.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1064
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Cross Platform -- Detect StringGadget Carriage Return Ke

Post by Randy Walker »

Having said that, confident that I have more than made my point, I have only one word to add to this thread...

Squeak :D
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1064
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Cross Platform -- Detect StringGadget Carriage Return Ke

Post by Randy Walker »

Uhhh Ohhhh :? Where is netmaestro?... I need to talk to him about his perfect workaround solution.
http://www.purebasic.fr/english/viewtop ... 13&t=49100

Ooopsie :oops: Did I say 'workaround' again? :oops:
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: Cross Platform -- Detect StringGadget Carriage Return Ke

Post by em_uk »

Do not want.
----

R Tape loading error, 0:1
Post Reply