ENTER and RETURN

All flavors welcome.
Forum rules
Be kind.
User avatar
richmond62
Posts: 4833
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

ENTER and RETURN

Post by richmond62 »

In both OXT Lite and the common legacy IDE the term:

shiftKey() is very useful in this sort of script:

Code: Select all

on keyDown
   if shiftKey() is down then 
      set the backGroundColor of this stack to red
   else
      set the backGroundColor of this stack to green
      end if
   end keyDown
BUT the terms enterKey() and returnKey() do not exist, which makes it extremely awkward for a stack to detect if an end-user has either the ENTER or the RETURN key depressed.

Would it be possible to implement enterKey() and returnKey() in OXT?

https://forums.livecode.com/viewtopic.php?f=7&t=39161

That would put LiveCode at a pip. 8-)
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4833
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ENTER and RETURN

Post by richmond62 »

The lack of these terms makes xTalk look a bit inconsistent.

Pushing things a bit further . . .

there would seem to be a similar problem with functionKey as one cannot do the same sort of thing as shiftKey(), altKey(), or optionKey(), and that is further complicated by the number of 'F' keys available on a user's keyboard.
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 3211
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: ENTER and RETURN

Post by tperry2x »

This should already exist in a slightly different form:

Code: Select all

on enterkey
   set the backGroundColor of this stack to red
end enterkey

on returnkey
   set the backGroundColor of this stack to green
end returnkey
Attachments
test.oxtstack
(426 Bytes) Downloaded 60 times
User avatar
tperry2x
Posts: 3211
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: ENTER and RETURN

Post by tperry2x »

You could also customise this further with alt, opt and function keys.
The function key doesn't generate a message by itself - it's a modifier, but you can detect if it's down then customise further if you want:

Code: Select all

on enterkey
   set the backGroundColor of this stack to red
end enterkey

on returnkey
   set the backGroundColor of this stack to green
end returnkey

on rawKeyDown theKey
   if theKey is 65505 or theKey is 65506 then -- left or right shift
      set the backGroundColor of this stack to yellow
   end if
   if theKey is 65513 or theKey is 65514 then -- left or right alt
      set the backGroundColor of this stack to orange
   end if
   if theKey is among the items of "65470,65471,65472,65473,65474,65475,65476,65477,65478,65479,65480,65481" then
      set the backGroundColor of this stack to purple
       -- tFunctionKey theKey -- or you could customise this further
   end if
   
   pass rawKeyDown
end rawKeyDown

command tFunctionKey theKey
   put theKey
   -- 65470  -- F1 key
   -- 65471 -- F2 key
   -- 65472 -- F3 key
   -- 65473 -- F4 key
   -- 65474 -- F5 key
   -- 65475 -- F6 key
   -- 65476 -- F7 key
   -- 65477 -- F8 key
   -- 65478 -- F9 key
   -- 65479 -- F10 key
   -- 65480 -- F11 key
   -- 65481 -- F12 key
end tFunctionKey
Attachments
test 2.oxtstack
(1.32 KiB) Downloaded 54 times
User avatar
richmond62
Posts: 4833
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ENTER and RETURN

Post by richmond62 »

I have played around with keyDowns and keyUps for nigh on 20 years (c.f. My Devawriter Pro), but the RETURN and the ENTER keys . . .

on enterKey

and

on returnKey

are all very well and good, what is extremely difficult with both the RETURN and the ENTER key is best explained by this script involving shiftKey():

Code: Select all

on keyDown
if shiftKey() is down then
  --do something
  else
  --do something else
  end if
  end keyDown
as returnKey() and enterKey() do not exist this sort of script is not really possible.
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 3211
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: ENTER and RETURN

Post by tperry2x »

You don't need the () at all because you aren't sending any arguments as functions to them.
You can handle the enterkey and returnkey directly as in my example, or did I miss something?

Code: Select all

on rawKeyDown theKey
if theKey is 65505 or theKey is 65506 then -- left or right shift
      set the backGroundColor of this stack to yellow
      put "Shift is down" into cd fld "text"
   else
      -- do something else
      put "Shift is not down" into cd fld "text"
 end if
   pass rawKeyDown
end rawKeyDown
   
test 3.oxtstack
(1.69 KiB) Downloaded 60 times
User avatar
richmond62
Posts: 4833
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ENTER and RETURN

Post by richmond62 »

Presumably you obtained 65505 and 65506 on Linux as LC/OXT will not deliver rawKeyCodes for ENTER or RETURN on MacOS. 8-)
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 3211
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: ENTER and RETURN

Post by tperry2x »

But of course :lol:

What happens if you put this in a card script?

Code: Select all

on rawKeyDown theKey
   put theKey
   pass rawKeyDown
end rawKeyDown
When you press the function keys then, do you get anything in the message box?

Anyway, you can handle enter and return directly.
User avatar
tperry2x
Posts: 3211
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: ENTER and RETURN

Post by tperry2x »

Tested on MacOS and works (enter and return)
osx-test.png
osx-test.png (96.45 KiB) Viewed 1863 times
test4.oxtstack
(687 Bytes) Downloaded 56 times
User avatar
richmond62
Posts: 4833
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ENTER and RETURN

Post by richmond62 »

Old Hat.

Nuffin for ENTER or RETURN.

MacOS 12
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 3211
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: ENTER and RETURN

Post by tperry2x »

richmond62 wrote: Wed Jun 19, 2024 4:36 pm Old Hat.
Nuffin for ENTER or RETURN.
MacOS 12
Slightly less old-hat (MacOS 10.15) - Works there too (enter, return, function keys)
less-old-hat.png
less-old-hat.png (75.69 KiB) Viewed 1848 times
Will test on MacOS (11+ something) when I get a chance tomorrow.
User avatar
richmond62
Posts: 4833
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ENTER and RETURN

Post by richmond62 »

Yup: just fine for finding the rawKeyCodes for every button EXCEPT for the RETURN and ENTER keys.
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 3211
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: ENTER and RETURN

Post by tperry2x »

How weird. Before I jump to conclusions that it's a MacOS incompatibility, - could you humor me and try plugging in a non-apple keyboard, just to see if that works? If it does, obviously that's not ideal - but I'm just trying to rule things out.

I'm also using what I'd call a UK keyboard, rather than a US or european one - don't know if that makes any difference.
This just perhaps raised another issue. I spent a good while looking on google and duckduckgo for what I'd call a 'normal uk' keyboard. Full size with number pad.
Their idea of what a standard 'uk english layout' is, is decidedly strange. Anyway, this is what I'm using (had to resort to taking a picture of the keyboard in question) and what OXT / LCC detects all the keypresses on. (Tried on MacOS machines, & Linux and works fine). The only thing I've not tried this on is Windows, which I may do in a moment. This keyboard layout is what I have on 5 computers here, (and over 146 in the school)... and it's what I'd consider 'standard'.
20240619_203201.jpg
20240619_203201.jpg (717.58 KiB) Viewed 1831 times
User avatar
richmond62
Posts: 4833
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: ENTER and RETURN

Post by richmond62 »

Jump to Conclusions as much as you like: it's at the very least a Mac 'incongruity' with other operating systems.
-
Screenshot 2024-06-19 at 22.39.28.png
Screenshot 2024-06-19 at 22.39.28.png (1.12 MiB) Viewed 1824 times
-
Mind you: do you know any recent systems or machines that have a SHIFT LOCK?
-
sob.png
sob.png (2.73 KiB) Viewed 1828 times
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 3211
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: ENTER and RETURN

Post by tperry2x »

I'm obviously lacking when it comes to my 'keyboard knowledge' :lol:
We could probably have a thread just on keyboards. Thing is, surely return should be return wherever you type it?
Anyway, all I do know for sure is that I didn't like the Apple ones, so they have long since been either sold, gotten rid of, found new homes for, or have found uses as a dedicated crumb and dust collector elsewhere.

That doesn't help much though, as most Mac users I'd assume are using some type of Apple keyboard, so I'd wonder why this isn't detected. (If that is indeed the case). More testing required...
User avatar
tperry2x
Posts: 3211
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: ENTER and RETURN

Post by tperry2x »

richmond62 wrote: Wed Jun 19, 2024 7:31 pm Mind you: do you know any recent systems or machines that have a SHIFT LOCK?
Only one, a Lenovo keyboard I have at work. I think it came off a gaming PC - but yeah, that says 'shift-lock' instead of 'Caps Lock'. There's also one that says 'Hard-lock' too, which does the same thing. Think that was an HP one.

Actually, you jogged my memory back to the Acorn and BBC computers. They had a shift lock key too, but I'm drifting off topic. (is that where your profile pic came from?)
acorn-bbc.png
acorn-bbc.png (296.33 KiB) Viewed 1820 times
Going to go and try an experiment on Windows now with the same keyboard... then maybe find an Apple one somewhere and see if it doesn't work on various Macs with OXT / LCC. Otherwise, it's potentially a MacOS system-version(jumping to conclusions)-thing...

Edit: Over in Microsoft-land, works in Windows with this keyboard, (in OXT Lite and LCC):
(keys pressed were return, enter, then F1 to F12 keys).
win-test.png
win-test.png (37.68 KiB) Viewed 1816 times
And just for the 'full set' of tests, here it is in Linux too:
linux-too.png
linux-too.png (30.26 KiB) Viewed 1812 times
At least the keycodes are consistent (I pressed Enter, then return on the mac test - oops, wrong way around). Anyway, the keycodes match up as I'd expect them to.

So, where does that leave me? - with more questions unfortunately.
I'll test on Sonoma (or Big Sur) or whatever I can lay my hands on regarding 'recent' MacOS. (I'll try with this keyboard and see if that works as a control test). If it does, then great... except not really as then it might mean it's an Apple keyboard issue.

If it doesn't work, then that leaves me with an OS issue possibly.

Either that, or a third possibility - although unlikely(?) - that perhaps LCC was never built with Mac users using a Mac keyboard in mind? I think this is unlikely as you mentioned they were using iMacs (and supposedly Apple keyboards) in their offices during LCC development(?)

Or a 4th possibility: Are you using some weird keyboard that perhaps OXT and LCC have taken an issue with? (Does your layout differ substantially from the keyboard pic I posted further up this page?) If you have a keyboard like mine, could you plug that in and test please.

A 5th possibility: Is this specific to your Mac? Could you test on any others please.

I'm just trying to rule out all possibilities, so as I say - please humor me. I think it'd be good to find out why it's not working. At the moment, I can't reproduce your error because it's just working like it should.
User avatar
OpenXTalkPaul
Posts: 2633
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: ENTER and RETURN

Post by OpenXTalkPaul »

The engine does send rawKey keycodes for Enter, Return, and a lot more on macOS, just the same as always regardless of platform. These numbers are embedded in the Engine itself. They are based on 1980s Unix key codes (we went over this 'over-there' not that long ago).
The only ones that don't send a key and rawKey code all on their own are the special modifier keys like (command/control, meta/hyperkey, option/alt), as I proved in that other thread even the capsLock key has a key-code.

Currently in my defaultsScripts for 'card' objects I have an 'on rawKeyDown' handler with super-long case-switch that handles just about every non-modifier key I think. In my musical toy stacks I've packed these all into arrays for fast-as-possible key code matching.

You can check 'the keysDown' in any handler, which allows for keyboard chording, so you could set up key combos like "Control+Command+Option+Shift+O+X+T" :)

So that makes it easy to roll your own version as a function:

Code: Select all

function isReturnKeyDown
  if "65293" is among the items of the keysDown then
      return true
  else 
     return false 
   end if
end isReturnKeyDown

function isEnterKeyDown
  if "65421" is among the items of the keysDown then
      return true
  else 
     return false 
   end if
end isEnterKeyDown
Of course using numbers instead of human understandable keyboard keyNames is very un-xTalk-ish, but the engine was first built in the early 1990s so that's the way it's been for over three decades (before Unicode even existed).
User avatar
tperry2x
Posts: 3211
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: ENTER and RETURN

Post by tperry2x »

Well, just tested on MacOS 12 Monterey - same keyboard.
macos-12-test.png
macos-12-test.png (296.43 KiB) Viewed 1761 times
That's as far MacOS-wise that I can test. All I can tell you is that the Returnkey and enterkey messages seem to be working as expected.
FourthWorld
Posts: 442
Joined: Sat Sep 11, 2021 4:37 pm
Contact:

Re: ENTER and RETURN

Post by FourthWorld »

richmond62 wrote: Wed Jun 19, 2024 1:15 pm Would it be possible to implement enterKey() and returnKey() in OXT?

https://forums.livecode.com/viewtopic.php?f=7&t=39161

That would put LiveCode at a pip. 8-)
That thread exhibits a common pattern of that community: someone has a question, the question needs clarification to understand more precisely the intended use, one person asked for that clarification, everyone else just guesses and spawns pages of subthreads with adventurous speculation, and the OP hasn't returned to clarify the use case.

In this case the clarification may be especially useful, because the initial description rests on a desire to use the Enter key in a way that runs counter to half a century of ingrained user expectations. The non-obviousness of a ready solution emerges from that, where xTalk messaging conventions, and the OS APIs on which they're based, reflect that most common, ingrained usage pattern.

We can see that even game designers, whose interaction models tend to be among those who have good reason to deviate from established convention, use other keys for prolonged input messaging, and tend to follow the ordinary path of leaving the Enter key for use as an instant trigger.

So until we learn why that OP wants to use the Enter key for the specified unusual purpose, the importance of revising the behavior of that key remains equal to the number of times that request has appeared in any xTalk community since HyperCard premiered in 1987. Anecdotally, from having read an uncommonly large percentage of communications across those communities and having worked with the dev teams of half of them, that number is one.

I hope expending resources on attempting to satisfy an undefined use case that AFAIK is unique in 35 years of xTalk for the purpose of putting anyone "at a pip" does not become an operational priority here.

In the other hand, if you have a specific need for something you're working on please share it.

Re priorities:

I recently spoke with a qualified developer about the possibility of addressing the need for recompilation for Apple's m-series processors. He passed, but AFAIK the need remains, yes?

For future discussions like that, which thread here offers the clearest description of the problem and remaining challenges?

I agree with Paul's assessment that, given Apple's history with architectural change, at this point we likely have somewhere between 18 and 36 months before any Intel-dependent engine will no longer run on the one OS where xTalks have ever had a foothold.

So we have time, and the sooner that challenge is addressed the more confidence folks can have in investing in building GPL software on this platform.
User avatar
OpenXTalkPaul
Posts: 2633
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: ENTER and RETURN

Post by OpenXTalkPaul »

FourthWorld wrote: Thu Jun 20, 2024 4:17 pm I recently spoke with a qualified developer about the possibility of addressing the need for recompilation for Apple's m-series processors. He passed, but AFAIK the need remains, yes?

For future discussions like that, which thread here offers the clearest description of the problem and remaining challenges?

I agree with Paul's assessment that, given Apple's history with architectural change, at this point we likely have somewhere between 18 and 36 months before any Intel-dependent engine will no longer run on the one OS where xTalks have ever had a foothold.

So we have time, and the sooner that challenge is addressed the more confidence folks can have in investing in building GPL software on this platform.
Having worked with keyDown/rawKeyDown plenty, trying for realtime input responsiveness (as mentioned like the way one would for using keyboard as game controller). I've had similar thoughts in regards to syntax inconsistency (another example: 'keysDown' message param will contain a character, but the keysDown contains rawKey code numbers and not characters). There's definitely been times I've thought it would be good to have the ability check using something like optionKeyDown() or returnKeyDown(). Like recently when I was building that On-Screen-Keyboard widget which is setup in a way to respond to both 'keyChar /keyNames and rawKey numbers that match the engines/XLib's numbers, which includes a default script that matches message (characters or names for non-printable char) OR rawKeyNumbers. But again it isn't like it's a lot of work to roll your own function for that (use 'the keysDown'), so I'd just do something like that and move on, never mentioning it in any forum anywhere.

I don't think the amount of use-cases people asked about in the last 35 years is a good measure of whether or not some syntax merits discussion, there could for example have been people with a desire to do some keyboard input tracking and didn't find an easy, sensible way to do it (using key code-numbers isn't sensible in an xTalk way, IMO) and so gave up. My biggest hope for OXT is that it enables someone to implement some app concept that no one has ever thought of before or implements an idea that has little to no common use-case commercial value but fills someone's unfulfilled need or desire.

Apple/M-series:

I figure Apple will be forced to support intel CPUs on the longer-side, more like 36 months rather than 12, and maybe longer with security patches. I'm at the point where I don't really care for Apple much anymore (which makes me a little sad, because I still prefer macOS over any other OS).

Yes, recompiling the OXT Mac engine as an Apple M-series native binary is still something OXT needs.
I was thinking maybe this could be crowd-funded and outsourced. I was also considering renting a M-series Mac cloud-computer, but I don't have the time (or really a need) to try to do all of that for myself.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests