How to detect user holding enter key down

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to detect user holding enter key down

Post by Klaus » Wed Jun 19, 2024 5:57 pm

dunbarx wrote:
Wed Jun 19, 2024 5:19 pm
Klaus.

The OP wrote:

Code: Select all

Is there a SIMPLE way that key holding could be detected in a way that a script could be activated to abandon the current task?
Didn't the OP want to be able to stop (or divert?) execution of a running handler by hitting the enter key?

Your gadget initializes the local variable, but that only stops execution of the handler after the "clean-up" lines are processed, not the handler itself the moment the enter key is pressed.

CAsba, please be precise. What do you want to do?

Craig
Oops, looks like I completely misunderstood the problem, sorry...

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: How to detect user holding enter key down

Post by richmond62 » Wed Jun 19, 2024 7:30 pm

Screenshot 2024-06-19 at 21.28.57.png
-
Script of button RUN:

Code: Select all

 
on mouseUp
   put empty into fld "VALZ"
   put 1 into KOUNT
   put 0 into A
   put 1 into B
   repeat until KOUNT > 1000
      put A + B into C
      put B into A
      put C into B
      put KOUNT & " : " & A into line KOUNT of fld "VALZ"
      wait for 25 ticks with messages
      add 1 to KOUNT
   end repeat
end mouseUp

on enterKey
   exit to top
end enterKey

Attachments
Fibonacci.livecode.zip
Stack.
(21.85 KiB) Downloaded 109 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: How to detect user holding enter key down

Post by dunbarx » Wed Jun 19, 2024 8:43 pm

Richmond.

I thought this was really a good one. The key of course is the "with messages", allowing LC to peek at the world it lives in and see if any enter keys are down. The only drawback, and it is a tiny one, is that the enter key has to be pressed during the wait time. Hardly an issue.

But there is something I do not understand, assuming anything I said above is valid. This handler does not respond to an enter key at all:

Code: Select all

on mouseUp
   repeat 1000
      repeat with y = 1 to 10
         put y into fld 1
         wait 5 -- cycle quickly through some integers
      end repeat
      wait 60 with messages --wait for the "10", ostensibly plenty of time to hit the enter key
   end repeat
end mouseUp 

on enterKey 
   exit to top
end enterKey
Craig

Cairoo
Posts: 112
Joined: Wed Dec 05, 2012 5:54 pm

Re: How to detect user holding enter key down

Post by Cairoo » Thu Jun 20, 2024 12:06 pm

Guys.

I think we've misunderstood what the OP wants. He seems to want to know how to handle the enter key only once while the enter key is down, i.e. do something when the enter key is pressed, but only once, until the enter key is released.

Gerrie

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to detect user holding enter key down

Post by FourthWorld » Thu Jun 20, 2024 5:24 pm

Cairoo wrote:
Thu Jun 20, 2024 12:06 pm
I think we've misunderstood what the OP wants.
Quite possibly. I've requested clarification on the use case, and look forward to the OP's return so we're no longer guessing.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: How to detect user holding enter key down

Post by dunbarx » Thu Jun 20, 2024 6:53 pm

CAsba, please be precise. What do you want to do?
Me too.

Craig

CAsba
Posts: 423
Joined: Fri Sep 30, 2022 12:11 pm

Re: How to detect user holding enter key down

Post by CAsba » Fri Jun 21, 2024 10:23 am

Hi guys,
Yes, I should have been more precise. I was concerned that user may hold enter key down, in reply to an ask dialog without entering a reply. I found that the following code ensures that it won'tb happen. Sorry to have used up your valuable time (I know - AGAIN).

Code: Select all

   put empty into cost
   repeat until cost is a number      
      ask "Enter the minimum purchaseable quantity of packs (numerals only)" titled field "fieldboxtitle"  of cd "template1"
      put it into cost       
      put cost into fld "fmin.purchqty"  
     if cost is not a number or cost <0 or cost is empty then
         put empty into cost
         answer "Try again. You must enter a numeral above zero."titled field "fieldboxtitle"  of cd "template1"  
      end if      
   end repeat 

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to detect user holding enter key down

Post by FourthWorld » Sat Jun 22, 2024 5:00 am

CAsba wrote:
Fri Jun 21, 2024 10:23 am
Hi guys,
Yes, I should have been more precise. I was concerned that user may hold enter key down, in reply to an ask dialog without entering a reply. I found that the following code ensures that it won'tb happen. Sorry to have used up your valuable time (I know - AGAIN).
No worries, I'm just glad you have a good solution. Bother us anytime.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: How to detect user holding enter key down

Post by dunbarx » Sat Jun 22, 2024 2:43 pm

Casba

So the whole thing was about data entry and validation, and nothing to do with holding down the enter key.

OK. Hard to communicate clearly.

At least we had a lively discussion about pressing control-type keys.

Craig

Post Reply