Keyboard access in LCB

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Keyboard access in LCB

Post by [-hh] » Tue Jan 30, 2018 1:30 pm

There is an undocumented handler "OnKeypress".
How can it be used?

Or, more general:
Which are the LCB handlers for getting keyboard input?
shiftLock happens

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Keyboard access in LCB

Post by mwieder » Thu Feb 01, 2018 3:32 am

There's an OnKeyPress handler in gradientrampeditor.lcb of the form

public handler OnKeyPress(in pKey as String) returns nothing
# stuff happens here
end handler

Here's the comment from the source for widget.lcb (not much help here):
Name: OnKeyPress
Type: message
Syntax: OnKeyPress <keyText>
Summary: Sent when a key is pressed while the widget has focus.
Parameters:
keyText(string): The key pressed

There's also an OnActionKeyPress handler, but it's not used anywhere at present, and there's no further information about it.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Keyboard access in LCB

Post by [-hh] » Thu Feb 01, 2018 10:55 am

Thanks Mark.

The OnKeyPress handler in gradientrampeditor.lcb is probably more kind of decoration there as it doesn't even use the parameter.

The description in widget.lcb sounds promising.
But with that there arises at once the question: How to set focus on a widget?
I tried with a timer, no success.

I can't believe that LC Builder is still ignoring the keyboard ...
shiftLock happens

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 474
Joined: Thu Sep 04, 2008 6:23 am
Location: Melbourne Australia

Re: Keyboard access in LCB

Post by jameshale » Fri Feb 02, 2018 1:46 am

onFocusEnter
OnFocusLeave
OnKeyPress
OnLayerChanged

the list goes on.

Check out the docs for "com.livecode.widget" in the LCB section of the dictionary.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Keyboard access in LCB

Post by [-hh] » Fri Feb 02, 2018 2:14 am

James, what a brilliant answer!!

Could you please tell me also which of all these entries gives any help to my questions?
I couldn't find anything to that:

How to get access to the keyboard in LCB?
How to set focus on a widget in LCB?
shiftLock happens

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 474
Joined: Thu Sep 04, 2008 6:23 am
Location: Melbourne Australia

Re: Keyboard access in LCB

Post by jameshale » Fri Feb 02, 2018 3:02 am

hmm.

none of the current widgets have text input (that I can see) except for the Android native field and I assume the soon to appear iOS/MacOS native fields.

Both these widgets will employe the FFI to hook into the java or Objective-C libraries which will allow for keyboard entry and, from reading through the Android native field lcb file, selection of keyboard type.

Perhaps this is only way planned?

and yes, I couldn't see a SET focus either.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Keyboard access in LCB

Post by mwieder » Fri Feb 02, 2018 3:38 am

If so, that leaves open the question of how to handle keyboard input / focus events for non-mobile applications.

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 474
Joined: Thu Sep 04, 2008 6:23 am
Location: Melbourne Australia

Re: Keyboard access in LCB

Post by jameshale » Fri Feb 02, 2018 3:41 am

There is a Mac single line field widget in the code base on github.
Currently above my pay grade to fully decipher :?

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Keyboard access in LCB

Post by mwieder » Fri Feb 02, 2018 3:58 am

! Good catch - I missed that one when I was searching for KeyPress, because it doesn't use OnKeyPress.

Looks to me like it's taking advantage of callbacks from the NSTextField object. The tests, though, don't do anything with keyboard input or focus, just 'set the text of widget...'.

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Keyboard access in LCB

Post by PaulDaMacMan » Wed Nov 01, 2023 10:48 pm

So I just started building a widget that is an On-Screen PC/Mac Extended Keyboard, the idea being to use this for visually/point-click setting of command keys, accelerator keys, or any other key associations...

It seems to me, and this thread seems to confirm this, that OnKeyPress never actually worked, despite it being mentioned in documentation (including that LCB tutorial). Even if you force the focusObject to be the Widget, LCB OnKeyPress handler never receives any key on/off messages.

Similarly OnActionKeyPress, OnFocusEnter, OnFocusLeave all seem to be non-functional, using LC Community Edition 9.6.3 (not sure how much LCB has improved, if at all, in the last 2 years).

HOWEVER, you can get key input working with widgets with this combination:

Code: Select all

public handler OnMouseEnter()
   set property "traversalOn" of my script object to "true"
   execute script "focus on me" in my script object
end handler
What this does is, whenever the cursor enters the widget:
- Sets the Widget traversalOn to true, which seems to be required for a Widget to receive any keyboard messages.
- Runs a script in the Widgets context to set the focusObject to the widget so that its receives the key messages before any other objects do.

Then you can use the regular key handling syntax: on keyDown, keyUp, rawKeyDown, commandKey, etc. handlers in the Widgets script just like any other control:

Code: Select all

on keyDown pKey
   put pKey into fld 1
end keyDown
To actually get messages INTO your widget from script, you can use 'OnDo' (and a big thanks to HH, RIP :( , for pointing this out) to send ANY data/string into your Extension for processing.

In your Widgets script:

Code: Select all

on keyDown pKey
   do keyDown && pKey in me 
end keyDown
In your Widgets LCB code you handle the 'do' message with an 'OnDo' handler:

Code: Select all

public handler OnDo(in pThingToDo as String)
   -------------- You would process 'pThingToDo' string "keyDown ?" here ------------
end handler
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Keyboard access in LCB

Post by richmond62 » Sun Nov 05, 2023 7:41 am

While the language previously known as Transcript is fairly well documented, is there a 'go to' place for LCB?

Is LCB a 'full' computer language (as in a full suit of clothes), just a set of hooks and buttons to connect LC with other things, or something midway between the two?

These probably come across as very goofy questions to 'club members', but they make sense to people like me looking through the fogged windows.

Queerly enough the last thing about LCB I could find on the LiveCode website was from 2019:

https://livecode.com/?s=LCB

and this: https://github.com/livecode/livecode/tr ... /lcb/notes

is about as easy to understand as being told to eat a tin of treacle with a feather:
-
Screenshot 2023-11-05 at 8.57.18.png
-
Certainly, without a knowledge of LCB one is stuck between using other people's widgets (and being unable to modify them), or not using widgets at all.

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Keyboard access in LCB

Post by stam » Sun Nov 05, 2023 2:01 pm

You are entirely correct… LCB seems to always have been treated as LC illegitimate love child. Quite capable but no one talks about it…

The problem is there is much less documentation for LCB which means you’d need to spend inordinately long trying to figure it out (and time is the one resource I can’t waste sadly). The few lessons and documentation that do exist are old, can be difficult to understand and even if you do, do not lead to wider understanding that would permit application to unrelated use cases.

What LCB really needs is a dedicated IDE with lots of prompts to help the learning dev do things correctly. But that’s a lot of work for little return I’m guessing.

But let’s be honest, any resemblance to LiveCodeScript is superficial at best - it is a different language that has been shoehorned into the LC IDE, when really it should it’s own IDE with built in conveniences to help produce externals rapidly and easily.

I for one would probably pay for such a product… but don’t expect that to ever materialise :(
Mainly because other than the resource required to build such an IDE, there is significant overlap with LiveCode’s native abilities, so would erode into maintaining the standard product.

Having said that, even a focused LCB IDE that would allow easy connectivity with external frameworks and libraries would have been a great addition…

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Keyboard access in LCB

Post by PaulDaMacMan » Fri Nov 17, 2023 11:00 pm

richmond62 wrote:
Sun Nov 05, 2023 7:41 am
While the language previously known as Transcript is fairly well documented, is there a 'go to' place for LCB?

Is LCB a 'full' computer language (as in a full suit of clothes), just a set of hooks and buttons to connect LC with other things, or something midway between the two?
Extension Builder, I would say is something in between?
it is a language, but it's not quite xTalk...although a good amount of effort was obviously put into making it look a bit like an xTalk.
It' could be categorized as a slightly lower level language, as it is statically typed, perhaps making it inherently less forgiving then the scripting engine (specially if you're like me and turn off "strict"" in the IDEs prefs UI). Maybe that's why this community seemed mostly not ready to adopt it.

it's s language that can be added to with syntax modules, and as demonstrated by Dr. Brett's 'Undergrowth' , the byte code modules it compiles can even be run on the command line with 'lc-run', sans the livecode engines involvement. Modules run in an 'infinite' state machine, a VM. With Foreign Function Interface, and some knowledge of a UI framework (like Apples Cocoa) you can even do graphical UI stuff and other things all without the LC Script Engine's UI framework being involved in any way (as an examples I built libraries that show PDFs and Audio Unit plugins that the script engine basically knows nothing about the state of the window they're being rendered into (by Cocoa not the Engine's renderer).
With Extension Builder FFI you can also bind to the internal C++ functions instead of an external library, like those of the scripting engines 'foundation' lib that has all sorts of functions (like for character encodings for example). Then there is syntax to bind that to a more xTalk like syntax (see the repo source LCB for language modules, syntax that builds some of LCB language itself as modules, adding syntactic sugar (yum)...
There's also two way communications possible between the scripting engine and the module VM. For example you in LCB you can execute LCS script 'execute "beep 3 --- or any other script" in my script object' and then get the result from within your modules LCB handler, and then Post messages like mouseUp with params [the click button] to the scripting engines message path, As shown with the 'do keyDown && pKey in widget 1' example I posted about, you can use LCB's OnDo to do its own text (script) parsing.

At one point, as I understood it the plan was to 'bootstrap' the whole shebang with LCB, basically rebuild the classic controls as widgets and then rebuild the entire Engine and all as LCB byte code modules, in retrospect that seems like a pipe dream.

I do agree that LCB was sort of always treated like the "illegitimate child" project. Although LC Mark, when pressed, has asserted that 'LCB' isn't going anywhere on several occasions. It's never felt ;complete', certainly not the documentation for it, and it's never seemed like any sort of priority for LC, which I think is a real shame. To me it's the best thing to happen to 'xTalk' in general since XCMDs/XFCNs, it really fills the same role (and the role of 'CompileIt!" too).

I do think it would be great to have dedicated IDE for Extension Builder, making things like adding a set of the standard properties to a widget as easy as picking a template, that would be great, and with a autocomplete, snippet scrapbook, etc. I've toyed with that idea a little in the past.
Until that happens, for an IDE, you can use Atom (although that's now an abandoned project), VSCode, BBEdit/TextWrangler, EMacs, and probably some others for editing your Extension Builder code, but it would be cool to have a LCB specific 'Script Editor' available directly inside the IDE.

Probably important to note that Extensions libraries can also be built with the regular scripting language, LCB not required. And as I understand it in newer versions of LC you can create script-based Widgets now without any LCB, but I don't know anything about that.
Last edited by PaulDaMacMan on Fri Nov 17, 2023 11:50 pm, edited 1 time in total.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Keyboard access in LCB

Post by PaulDaMacMan » Fri Nov 17, 2023 11:23 pm

There was an effort on GitHub to build a 'LiveCode Builder - The Missing Manual as a Wiki (but it looks like that work stalled).
https://github.com/macMikey/LCB-missing-manual/wiki
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Post Reply

Return to “LiveCode Builder”