Page 1 of 1

wait with Key speed

Posted: Tue May 17, 2016 7:46 am
by samjith
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

Re: wait with Key speed

Posted: Tue May 17, 2016 9:29 am
by istech
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

Re: wait with Key speed

Posted: Tue May 17, 2016 9:47 am
by samjith
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?

Re: wait with Key speed

Posted: Tue May 17, 2016 11:38 am
by samjith
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

Re: wait with Key speed

Posted: Tue May 17, 2016 1:34 pm
by istech
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.

Re: wait with Key speed

Posted: Tue May 17, 2016 2:30 pm
by samjith
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

Re: wait with Key speed

Posted: Tue May 17, 2016 3:58 pm
by jacque
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

Re: wait with Key speed

Posted: Wed May 18, 2016 1:07 pm
by samjith

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

Re: wait with Key speed

Posted: Wed May 18, 2016 3:46 pm
by FourthWorld
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.

Re: wait with Key speed

Posted: Thu Jun 09, 2016 1:57 pm
by kaveh1000
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. ;-)

Re: wait with Key speed

Posted: Thu Jun 09, 2016 2:40 pm
by Newbie4
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

Re: wait with Key speed

Posted: Thu Jun 09, 2016 4:26 pm
by dunbarx
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

Re: wait with Key speed

Posted: Fri Jun 10, 2016 9:45 am
by samjith
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