AutoHotkey Community

It is currently May 27th, 2012, 3:03 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: March 17th, 2010, 9:07 pm 
Hello,

I'd like to move the cursor in a text filed to the right until a special charactor was found. How can I achive this ? I Just dont know the name of a function which reads the next char.

Thanks in advance


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 11:05 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6071
Location: San Diego, California
GuestUsr wrote:
Hello,

I'd like to move the cursor in a text filed to the right until a special charactor was found. How can I achive this ? I Just dont know the name of a function which reads the next char.

Thanks in advance
Your question is somewhat muddled by the facts of AHK.

"Cursor" implies a screen reference in a program. Depending on the program, it may be easy or difficult to get the text.

But first please clarify:

Are you trying to read characters on screen, in an application (such as Notepad)?

Are you trying to read characters in a text file, by reading the file with AHK?


Report this post
Top
 Profile  
Reply with quote  
 Post subject: real purpose
PostPosted: March 20th, 2010, 12:56 am 
What i really want to do is the following:

I am using the program 'texnicCenter' for writing some latex.
In latex math codes are sorrounded by the character '$'
So I'd like to be able to jump to the next '$'. Especiall if I press the shift key,
i want all the math code between the two '$' characters being marked.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 8:47 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Doesn't pressing ctrl-shift-left work in the program, it does in "regular" editors to select a word. Does a mouse double or tripple click select a word?

If not all I can think of is starting to select text and copy the text to the clipboard each time until you see $ is the last char. Start notepad type some test and place the caret (cursos is your mouse, caret is the blinking thingy where your text appears). Place caret directly after the first $ and run this script ...
Code:
SetBatchLines, 0
WinActivate Untitled ; activate notepad
sleep 2000
Loop
{
   Send {Shift down}
   Send {right}
   Send ^C
   sleep 10
   StringRight, test, clipboard, 1
   If (Test = "$")
      {
      Send {left}
      Send ^C
      sleep 10
      Send {Shift up}
      Break
      }
      
}
MsgBox % clipboard   

Esc::ExitApp
:?:

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 9:49 pm 
Quote:
Doesn't pressing ctrl-shift-left work in the program, it does in "regular" editors to select a word. Does a mouse double or tripple click select a word?

No, because there is not just only one word between those characteros but serveral ones.

Code:
#MaxThreads 2
^+r::
keepRunning = false
MsgBox "stoppe"
return


^r::
If keepRunning = true
{
   MsgBox "abbruch"
   keepRunning = false
   return
}


KeepRunning=true
SetBatchLines, 0
WinActivate Untitled ; activate notepad
Loop
{
   if keepRunning = false
   {
     Send {Shift up}
    Break
    }
   Send {Shift down}
   Send {right}
sleep 1000
   Send ^C
   StringRight, test, clipboard, 1
   If (Test = "$")
      {
      Send {left}
      Send ^C
      sleep 10
      Send {Shift up}
      Break
   }     
}
KeepRunning = false

return


Here is what i got so far.
Though, I'm still not quite happy as it is very slow and it doesnt work if i drop "sleep 1000" before pressing ^C, if ^+r is supposed to stop the loop.
[/code]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 11:37 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Look at the faq there is an example with a loop and stopping it. http://www.autohotkey.com/docs/FAQ.htm#repeat

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 12:58 am 
I used but its still not ok


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 8:54 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Post you entire code, but you can try this to speed it up, rather than 1 key it checks 5
Code:
Step=5 ; change value here to make it faster/slower
Loop
{
   Send {Shift down}
   Send {right %step%}
   Send ^C
   sleep 10
   StringRight, test, clipboard, %step%
   IfInString,Test,$
      {
       x:= step - InStr(Test, "$") + 1
       Send {left %x%}
       Send ^C
       sleep 10
       Send {Shift up}
       Break
      }
      
}


Or with ctrl-shift-left navigation
Code:
Loop
{
   Send {Shift down}
   Send ^!{right}
   Send ^C
   sleep 10
   IfInString,Clipboard,$
      {
       x:= StrLen(Clipboard) - InStr(Clipboard, "$") + 1
       Send {left %x%}
       Send ^C
       sleep 10
       Send {Shift up}
       Break
      }
}

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 6:26 pm 
@hugov thanks alot for your tweak. Speed is now sufficient.

What makes you think I didnt post the entire code ?
Is something missing ?

Nevertheless stoping the process is still buggy.

When pressing ^r, Shift down is being hold,
and I'd like to stop the loop by pressing ^r again.
As Shift down is active, I used the hotkey ^+r to stop the loop,
s.th. it will be invoked when I press ^r while the other Thread is still proceeding in the loop.
Unfortunately it's not very reliable. It works only if sleep inside the loop is sufficient long.

I think there is still a Thread-problem. I guess it just works when the Thread running the loop is suspended by the 'sleep' command.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 7:56 pm 
and it does not work any program other than notepad.
Like in firefox


Report this post
Top
  
Reply with quote  
PostPosted: March 22nd, 2010, 2:04 pm 
With the help of some people it works now as it should, in notepad.
So by pressing ^r it start to search for '$' and stops if you press ^r again.


Code:
$^+r::
{
   keepRunning := false
}
return



$^r::
{
        If ( !keepRunning)
        {
    keepRunning := true
   }

   shift= 10
   Loop
   {
      If ( keepRunning )
      {
         Send {Shift down}
         Send {right %shift%}
                sleep 10
         Send ^C

         StringRight, test, clipboard, shift
         IfInString,Test,$
         {
               x:=shift - InStr(Test, "$") + 1
               Send {left %x%}
               Send ^C
               sleep 2
         Send {Shift up}
               Break
            }     
        }
          Else{
               Send {Shift up}
               Break
        }
      

   }

        KeepRunning := false
}
return



Unfortunately it does still does not work in teXnicCenter or for example in firefox. The problem is that for some reason, ^c does not work. How can i fix this ?


Report this post
Top
  
Reply with quote  
 Post subject: got it
PostPosted: March 24th, 2010, 10:18 am 
this one works:

Code:
#MaxThreadsPerHotkey, 2
$^+r::
{
   keepRunning := false
}
return



$^r::
{
        If ( !keepRunning)
        {
    keepRunning := true
   }

   shift= 10
   Loop
   {
      If ( keepRunning )
      {
         Send {Shift down}
         Send {right %shift%}
                sleep 10
      Send {Shift up}
      Send ^c

         StringRight, test, clipboard, shift
         IfInString,Test,$
         {
         Send {Shift down}
               x:=shift - InStr(Test, "$") + 1
               Send {left %x%}
               Send ^C
               sleep 2
         Send {Shift up}
               Break
            }     
        }
          Else{
              Send {Shift up}
               Break
        }
      

   }
        KeepRunning := false
}
return


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: rbrtryn and 29 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group