Preventing duplicate input

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

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Preventing duplicate input

Post by jmk_phd » Sun Oct 20, 2019 12:10 am

Craig and Bogs and all --

Sorry to cause so much anxiety. (In my day job as a psychologist, my role is to help reduce anxiety.) Apologies especially to contributor richmond62 for losing a few hours of sleep.

As an initial experiment, I changed all mouseDown and keyDown handlers/commands for the first ten items/cards to mouseUp and keyUp -- enough items to test whether this corrected the problem with two rapid key presses or button clicks. A quick double-press/double-click still resulted (for example) in the first press/click being recorded as the response to card/Item1, then advancing quickly to card/Item2 and registering the same response, then finally displaying card/Item3 that properly awaits a response.

I understand the wisdom of Craig's insistence that identifying the problem requires inspecting the actual code. I've been reluctant to have forum participants wade through the many hundreds of lines involved in processing the mouse/keyboard input.

I will try to recreate and post a pared-down version of the stack that just addresses the problem.

Thanks so much to everyone.

jeff k

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Preventing duplicate input

Post by bogs » Sun Oct 20, 2019 9:36 am

jmk_phd wrote:
Sun Oct 20, 2019 12:10 am
Sorry to cause so much anxiety. (In my day job as a psychologist, my role is to help reduce anxiety.)
Well, I'm not anxious as much as curious, which thankfully I don't need to be cured for yet, but I doubt an apology is necessary :D

Look forward to seeing an example that demonstrates this behavior, since I wasn't able to create a (simple) stack that could do what your describing in an unintentional way, short of having doubleDown, doubleUp, or doubleClickInterval handlers introduced.
Image

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

Re: Preventing duplicate input

Post by richmond62 » Sun Oct 20, 2019 10:46 am

Sorry to cause so much anxiety.
You didn't, in my case at least, I rather enjoyed the meditative experience. 8)

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

Re: Preventing duplicate input

Post by richmond62 » Sun Oct 20, 2019 10:51 am

I do think changing the keyDowns to keyUps should make a significant difference as one cannot
keep "pressing up" on a key.

However that was not the OP's Q: it related to keyDowns.

Of course one could poll the state of a mouse using mouseStillDown,

err . . . and . . . maybe it is time to start badgering the Mothership to introduce a keyStillDown . . .

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Preventing duplicate input

Post by bogs » Sun Oct 20, 2019 11:08 am

richmond62 wrote:
Sun Oct 20, 2019 10:51 am
I do think changing the keyDowns to keyUps should make a significant difference as one cannot
keep "pressing up" on a key.
However that was not the OP's Q: it related to keyDowns.
The question about up and down came around in relation to the thread by the OP here,
I've indeed debated using keyUp or mouseUp vs. keyDown and mouseDown, but found not sufficient guidance in the online LC Dictionary to decide how best to handle this problem.
As you say, you can not keep pressing up on either a key or mousebutton, so it seems the intuitive solution, provided you don't have doubleClick or press handlers intercepting multiple click/key press events, any of those events should drop into the ether.
Image

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Preventing duplicate input

Post by jmk_phd » Mon Oct 21, 2019 7:13 am

To all --

I've stripped out from the app all but the custom props and code that relate directly to the duplicate input issue -- eliminating the routines that handle other test item formats, timing, scoring, and the option to redisplay and edit a previous item.

This new mainstack includes only the first six items of the test, plus new "BeginTest" and "EndTest" cards to bracket the start and end of the test.

The script for each test item/card is identical except for the inserted text. The script for all buttons are identical as well.

If you click or keypress once when a test item is presented, the response will be registered and the test will advance properly to the next item.

However if (for example) you either click or keypress again quickly on the first item, it will save the initial response, then automatically advance to the second item and apply that initial same response to this second item, then quickly advance again to display the third item.

I'm uploading this bare-bones livecode file so you can try and examine it for yourself. There's probably a very simple solution.

Thanks. jeff k
EAS-SABE 210 (demo).livecode.zip
(25.41 KiB) Downloaded 166 times

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Preventing duplicate input

Post by jmburnod » Mon Oct 21, 2019 1:39 pm

Hi Jeff
Your stack contains the same script for all cd except contents.
For example you may delete keyup messae of all cds and move it in stack script.
Regarding the contents you may use custom prop or external files.
I think you may extract data from each script cd to set it as a list to use for a custom prop or external file.
Once you get it you can have all scripts in stack.
You may even have only one cd and import its content for each items.
After several tests, Bernd's suggestion seems the better way to avoid double input.
I hope this help
Kind regards
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Preventing duplicate input

Post by dunbarx » Mon Oct 21, 2019 2:24 pm

Hi.

This is a generic offering, since I did not look at the stack you posted. All this does is trap double clicks. Should solve your issues, though.

Make a new stack with a few cards. Identify each card somehow, so you know where you are. Put this in your stack script:

Code: Select all

on mouseUp
   go next cd
end mouseUp

on mouseDoubleUp
end mouseDoubleUp

on mouseDoubleDown
end mouseDoubleDown
Note that it will not prevent the user from simply clicking continuously. That requires an intervention on that user, and more work in the stack script.

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Preventing duplicate input

Post by bn » Mon Oct 21, 2019 2:46 pm

Hi Jeff,

in the stack script

Code: Select all

   wait 500 milliseconds
   get flushEvents("all") -- <-- ADD This
   doGoNextItem tThisItemNum
end doLickertResponseBtn
seems to do the trick

Kind regards
Bernd

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Preventing duplicate input

Post by bogs » Mon Oct 21, 2019 7:27 pm

dunbarx wrote:
Mon Oct 21, 2019 2:24 pm
This is a generic offering, since I did not look at the stack you posted. All this does is trap double clicks. Should solve your issues, though.
I actually did test it, by copying and pasting it into the main stack level at the bottom, I was unable to answer more than one card at a time after doing so, so I would say Craig's offering is certainly the easiest way to stop the erratic mouse behavior on the double click.

Bernd's solution resolves all issues and may be a bit easier.
Image

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Preventing duplicate input

Post by jmk_phd » Tue Oct 22, 2019 1:53 am

Thanks so much to everyone who has contributed to addressing this problem for me.

As it turns out, Bernd's solution to insert flushEvents() just prior to a "go to next cd" -- which actually (in my own ignorance) both he and forum member -hh had suggested earlier in this thread -- seems to work just fine. (Trapping a mouseDoubleUp and mouseDoubleDown was indeed effective in blocking multiple quick button clicks from triggering a "go to next cd" , but unfortunately did not prevent multiple quick number-key presses from sending mouseUp messages that improperly advanced to the next cd.)

Inserting flushEvents("all") in the three handlers that process test input -- just where Bernd indicated -- so far has had no unintended consequences, so I'm confident that this was sufficient to resolve this vexing problem.

Thanks also to Jean-Marc's suggestions for streamlining the code, which I'm sure reflect best and most efficient programming practices. It's just that the program is required to do so much more than illustrated in my bare-bones demo -- along with ever-changing requirements and feature requests by my client, as well as lots of conditionals to handle numerous variables -- that the current design seems the most workable strategy.

If that client outlives me, he'll need to hire a LiveCode programmer to do future updates, so I've been scrupulous in commenting the code and in making it as easy as possible to follow.

Best wishes to all.

jeff k

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Preventing duplicate input

Post by jmburnod » Tue Oct 22, 2019 10:12 am

Hi Jeff,
I allow myself to insist because you point two arguments to make your code easier to modify by a other developper. I also insist because i lost a lot of time when i began coding.
along with ever-changing requirements and feature requests by my client, as well as lots of conditionals to handle numerous variables
need to hire a LiveCode programmer to do future updates,
As Bernd said you may put your keyup handler in the stack script and delete your keyup handler in all cd script. That will be easier to manage for your succesor.
I also pointed content managing. I you use a custom prop to store the content of each cd you will may delete all cds script.
All the best
Jean-Marc
https://alternatic.ch

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Preventing duplicate input

Post by jmk_phd » Tue Oct 22, 2019 6:40 pm

Jean-Marc --

I truly appreciate your wise programming advice as regards simplifying the code and will indeed follow best practices when designing an application from scratch.

The problems in this case were many: What began as the simple administration of a series of test questions (illustrated in the stripped-down demo I'd uploaded) required more and more modifications/features as the client insisted that the program include both English and Spanish content (including adult vs. adolescent and Spanish gendered male vs. female versions), be able to reverse, redisplay, and change a previous cd response, interrupt the test in case of an incorrect response, resume a discontinued test from the last version saved to disk, score a raw saved .csv file, and generate a test report from a saved .csv scored file.

Consequently, in this case, moving the keyup handler to the mainstack script would've required lots of conditional statements that I believe actually might have confused the code. Also, unlike the the sample items in my posted demo, many other test items require complex conditionals not suited to mainstack custom props.

I will strive to employ your best practices in future apps.

Thanks. jeff k

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”