wait with Key speed

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

Post Reply
samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

wait with Key speed

Post by samjith » Tue May 17, 2016 7:46 am

Hi,

I have a text field, with code

Code: Select all

on textchanged
  runfile
end textchanged
When i write something on the field, it will runfile (on each key).

The problem is the "Speed".

if i wrote something very fast on the field, it will takes too much time. is there any way to do like this?

wait .2 seconds and if no keydown then it runfile.


Thanks in advance

Samjith

istech
Posts: 211
Joined: Thu Sep 19, 2013 10:08 am

Re: wait with Key speed

Post by istech » Tue May 17, 2016 9:29 am

samjith wrote:Hi,

I have a text field, with code

Code: Select all

on textchanged
  runfile
end textchanged
When i write something on the field, it will runfile (on each key).

The problem is the "Speed".

if i wrote something very fast on the field, it will takes too much time. is there any way to do like this?

wait .2 seconds and if no keydown then it runfile.


Thanks in advance

Samjith

try using rawKeyDown

Not sure if this is what you need

on rawkeydown
send x to me in 0 seconds
pass rawkeydown
end rawkeydown

on x
lock messages
lock screen
repeat with i = 1 to the number of characters in me
--do something you want to do on each char
runfile
end repeat
unlock messages
end x
Last edited by istech on Tue May 17, 2016 9:57 am, edited 1 time in total.

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: wait with Key speed

Post by samjith » Tue May 17, 2016 9:47 am

are you sure?

I used rawkeydown, but still worried about the speed.

I don't need to run the command "runfile" if i type in the field fast.
but i need to run command "runfile" if i type in the speed with delay


Could you give a sample piece of code. How it look likes?

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: wait with Key speed

Post by samjith » Tue May 17, 2016 11:38 am

Not sure if this is what you need

on rawkeydown
send x to me in 0 seconds
pass rawkeydown
end rawkeydown

on x
lock messages
lock screen
repeat with i = 1 to the number of characters in me
--do something you want to do on each char
runfile
end repeat
unlock messages
end x
No, this is not

i will tell an example

if i write text "samjith" in the field with 5 second (not very speed), i need to execute runfile in between each char
and
if i write text "samjith" in the field with 1 second (very expert in typewriting), i need to execute runfile at last

istech
Posts: 211
Joined: Thu Sep 19, 2013 10:08 am

Re: wait with Key speed

Post by istech » Tue May 17, 2016 1:34 pm

I would need to hear some more of what you are trying to achieve. As I am not sure.

But from what you have said the word/text would need to be checked against another word/text after 1 second

If the word/text is not complete after 1 second then use runfile after each text.

Is that correct?

maybe try

local nexpert
on openfield
put false into nexpert
end openfield

on rawkeydown
if nexpert is false then
send "expert" to me in 1 second
put true into nexpert
else
if nexpert is "noexpert" then
send x to me in 0 seconds
pass rawkeydown
end if
end if
pass rawkeydown
end rawkeydown

on expert
if fld "a" = "expert" then --expert
answer "runfile expert"
else
put "noexpert" into nexpert
end if
end expert

on x
lock messages
lock screen
repeat with i = 1 to the number of characters in me
--do something you want to do on each char
answer "runfile not expert"
--however the words already type would need to be handled. maybe loop through them adding your runfile handle
end repeat
unlock messages
end x

Maybe someone has a better route.
Last edited by istech on Tue May 17, 2016 4:29 pm, edited 1 time in total.

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: wait with Key speed

Post by samjith » Tue May 17, 2016 2:30 pm

If the word/text is not complete after 1 second then use runfile after each text.
not each text.

i want to run once after i comple my typing

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: wait with Key speed

Post by jacque » Tue May 17, 2016 3:58 pm

It is common to use a closefield handler for things like this. Closefield is sent when the user exits the field after the text has changed.

Code: Select all

on closefield
  runfile
end closefield
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: wait with Key speed

Post by samjith » Wed May 18, 2016 1:07 pm

Code: Select all

on closefield
  runfile
end closefield
This is good,
but when i change my focus to desktop (by alt+tab), it will not run

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

Re: wait with Key speed

Post by FourthWorld » Wed May 18, 2016 3:46 pm

samjith wrote:

Code: Select all

on closefield
  runfile
end closefield
This is good,
but when i change my focus to desktop (by alt+tab), it will not run
If the text of the field has changed that would be a bug, since the field loses focus when the app is switched into the background, and as such should fire a closeField message. If that's the case please file a bug report on that.

If the field contents have not changed the closeField message will not be sent, but an exitField message will be sent instead.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: wait with Key speed

Post by kaveh1000 » Thu Jun 09, 2016 1:57 pm

I think Samjith did not explain the problem clearly.

I am working with Samjith and what we need is that as the usr is typing into a field we want to take that text and run another script with it. But the second script is quite intensive and when it runs it interrupts touch typing. So we want it to run only when the user has not typed for say .2 seconds, i.e. stopped touch typing.

We have tried "idle" and "wait" in different ways but with not success. I know it can be done but can't put my finger on it. ;-)
Kaveh

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: wait with Key speed

Post by Newbie4 » Thu Jun 09, 2016 2:40 pm

Look up the ticks in the dictionary. Why not do something like this:

Code: Select all

global lastKey
on textChanged
   if  fld "a" = "" then put the ticks into lastKey
   if the ticks - lastKey  > 12
         runfile
   end if
   put the ticks into lastKey
end textChanged
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

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

Re: wait with Key speed

Post by dunbarx » Thu Jun 09, 2016 4:26 pm

Hi.

Try this. On a new card make two fields. The second field is just to see what is going on. In the script of the flrst field, the one you will be typing into:

Code: Select all

global tTime

on keyDown tkey
   put "" into fld 2
   checkDelay tKey
end keyDown

command  checkDelay tKey
   put tKey after me
   put the ticks - tTime into fld 2
   if the ticks - tTime > 55 then
      doProcess
   end if
   put the ticks into tTime
end checkDelay

command doProcess
   put random(999)  into line 2 of fld 2
end doProcess
The "55" is to be able to see what happens if you type quickly or wait just a little. I do not know what the right time for you is.

Craig Newman

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: wait with Key speed

Post by samjith » Fri Jun 10, 2016 9:45 am

Hi,

The below mentioned code works partially for now. Something like this code is required for me.

Code: Select all

on textchanged
     set the backgroundcolor of me to lightblue
end textchanged

on idle
   set the idleRate to 500
   if  the backgroundcolor of me is lightblue then
      runfile
      set the backgroundcolor of me to lightyellow
   end if 
end idle
Thanks

Samjith

Post Reply