RawKeyDown and focused object: something fishy

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
trevix
Posts: 962
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

RawKeyDown and focused object: something fishy

Post by trevix » Sun Mar 24, 2024 6:08 pm

Hello.
You may find the attached test stack a little strange (tested only on OSX as of now, LC10,OSX14.3.1).
This stack is useful to me to test a string keyboard input packet, of a fixed lenght, defined as such because of the first chosen char, while having in the card other text input fields or focusable controls, where the user may be doing some activity.
In reality the string packet will be sent with Bluetooth from a HID device.

To test the stack:
1 - Open the stack on development
2 - press the "Chose BTcode char" button, typing a single char (for example "x")
3 - Mouse click on the card, so as to deselect everything (on the log the "focuseObject" will correctly write the card being focused)
PS: I always found this behaviour strange, since only controls with traversalOn property = true should receive focus...bah.
4 - Type "x" (or whatever your chosen char) followed by 4 other chars
EXPECTED RESULT: when the string is 5 chars long it will trigger the "Completed" response (see the log)
OBSERVED RESULT: same, correct

5 - Now go to card 2 (use the segment widget) and do again point 4 (Type "x" (or whatever your chosen char) followed by 4 other chars)
Note that on card 2 there are not focusable controls.
EXPECTED RESULT: when the string is 5 chars long it will trigger the "Completed" response (see the log)
OBSERVED RESULT: same, correct

NOW:
6 - back to card 1
7 - type something on the "Text Mac Fld" and leave there the insertion point
8 - Repeat point 4
OBSERVED RESULT: same, correct: even if the unlocked filed is selected, with an insertion point, the "Completed" response will be triggered

HERE WE GET TO THE POINT
9 - go to card 2 (you left the field of card 1 still focused)
10- Repeat point 4
EXPECTED RESULT: when the string is 5 chars long it will trigger the "Completed" response (see the log)
OBSERVED RESULT: no RawKeyDown input get received by the card
Note that "focusedObject" returns correctly the card name

I believe this last wrong behaviour depends somehow from not having a focusable object in the card. But still I don't understand why it works on points 5.
Also, if you repeat point 6-7-8 and you go to card 3, it will work just by having a focus on fld "TestField" and "Focus on nothing" on the on OpenCard,

Someone can explain me this behaviour and suggest some solutions?
Thanks
Trevix
Last edited by trevix on Sun Mar 24, 2024 6:29 pm, edited 2 times in total.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

trevix
Posts: 962
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: RawKeyDown and focused object: something fishy

Post by trevix » Sun Mar 24, 2024 6:09 pm

Here is the test stack.
Attachments
TestRawInput.livecode.zip
(3.2 KiB) Downloaded 16 times
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

trevix
Posts: 962
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: RawKeyDown and focused object: something fishy

Post by trevix » Sun Mar 24, 2024 6:19 pm

I just found this bug 23783
https://quality.livecode.com/show_bug.cgi?id=23783
is it related?
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

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

Re: RawKeyDown and focused object: something fishy

Post by richmond62 » Sun Mar 24, 2024 6:28 pm

OK:
1 - Open the stack on development
2 - press the "Chose BTcode char" button, typing a single char (for example "x")
3 - Mouse click on the card, so as to deselect everything (on the log the "focuseObject" will correctly write the card being focused)
-
Screenshot 2024-03-24 at 19.26.08.png
-
But I do not understand this:

"4 - Type "x" (or whatever your chosen char) followed by 4 other chars"

Where should I type that?

trevix
Posts: 962
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: RawKeyDown and focused object: something fishy

Post by trevix » Sun Mar 24, 2024 6:32 pm

Hello.
When you press the button "Chose BTcode char", you will be asked to type a single char, that will be used to identify the start of the string.

Then remove focus and with your keyboard type the same char followed by any other chars: the RawKeyDown will catch your typing even with no field selected.

Reading again about bug 23783, I really think that we are talking of the sam June 2022 bug, not solved even on LC10
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

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

Re: RawKeyDown and focused object: something fishy

Post by richmond62 » Sun Mar 24, 2024 6:39 pm

I think I have got my feet all mixed up:
-
Screenshot 2024-03-24 at 19.38.06.png

trevix
Posts: 962
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: RawKeyDown and focused object: something fishy

Post by trevix » Sun Mar 24, 2024 6:57 pm

May be that if I explain what I am trying to achive, my post will be more clear.

We are preparing, in a Bluetooth device, a new firmware that will allow it to behave as a keyboard, once paired to a computer or mobile.
In this way I will not need an SDK to do the BT pairing. Will do it in the OS, like if it was a BT speaker or a mouse or a "keyboard". Very handy.

The idea is that an action on the Bluetooth device will send a string of text.
This string is composed by a "first char" and a "MAC address" (in my example stack is only 4 char long).
The first char (to be decided) will identify what follows as coming from our device. We will need a particular char (255byte) not usually typed by a user.
The MacAddress is used to identify that particular device from others of the same kind.

So, while a user may be typing, clicking or doing something else on LC, if the RawKeyDown detect the correct chosen char, it will collect what follows (the MAC address) and eventually do something with it.
Otherwise the typing or other activity will behave normally.
Off course, this must work on ANY card where we have a RawKeyDown command, no matter what kind of control, widget or else is in that card.
I hope to have bee a little more clear.
Thanks
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

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

Re: RawKeyDown and focused object: something fishy

Post by stam » Sun Mar 24, 2024 9:03 pm

Hi Trevix,

I too replicated your issue but also had issues where it would just stop logging (usually after typing the x).

After changing your rawKeyDown handlers to rawKeyUP, it seems to do what you're asking.

Not sure if that helps you...

S.

trevix
Posts: 962
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: RawKeyDown and focused object: something fishy

Post by trevix » Mon Mar 25, 2024 2:14 pm

RawKeyUp is of no use to me since, if any text input Field is selected, the chosen char would be inserted also on this, not only on the log.
The general idea of all this, is to address a specified char to the log and any other char to a control, if available, or to nothing.

I prepared a simplified stack and decided to post on the Bug quality center:
https://quality.livecode.com/show_bug.cgi?id=23783
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

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

Re: RawKeyDown and focused object: something fishy

Post by stam » Mon Mar 25, 2024 2:55 pm

trevix wrote:
Mon Mar 25, 2024 2:14 pm
RawKeyUp is of no use to me since, if any text input Field is selected, the chosen char would be inserted also on this, not only on the log.
The general idea of all this, is to address a specified char to the log and any other char to a control, if available, or to nothing.

I prepared a simplified stack and decided to post on the Bug quality center:
https://quality.livecode.com/show_bug.cgi?id=23783
Hope they can advise or fix, it's a weird one.

But regarding your solution - it may be possible to set the text of in the field minus the chosen char if it's the first char in the sequence - but is a bit more cumbersome.

For example - if you set the lockText user test field to true and in the rawKeyUp handler add:

Code: Select all

try; put char 2 to -1 of sString before the focusedObject; end try
just before

Code: Select all

put empty into sString
That kinda simulates more or less what you want? (only the text is entered in one go, rather than 1 char at a time).

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”