AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Read the characters after the cursor and move it

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
GuestUsr
Guest





PostPosted: Wed Mar 17, 2010 8:07 pm    Post subject: Read the characters after the cursor and move it Reply with quote

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
Back to top
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Wed Mar 17, 2010 10:05 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
GuestUsr
Guest





PostPosted: Fri Mar 19, 2010 11:56 pm    Post subject: real purpose Reply with quote

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.
Back to top
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Sat Mar 20, 2010 7:47 am    Post subject: Reply with 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?

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
Question
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
GuestUsr
Guest





PostPosted: Sat Mar 20, 2010 8:49 pm    Post subject: Reply with quote

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]
Back to top
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Sat Mar 20, 2010 10:37 pm    Post subject: Reply with quote

Look at the faq there is an example with a loop and stopping it. http://www.autohotkey.com/docs/FAQ.htm#repeat
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
GuestUsr
Guest





PostPosted: Sat Mar 20, 2010 11:58 pm    Post subject: Reply with quote

I used but its still not ok
Back to top
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Sun Mar 21, 2010 7:54 am    Post subject: Reply with quote

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 Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
GuestUsr
Guest





PostPosted: Sun Mar 21, 2010 5:26 pm    Post subject: Reply with quote

@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.
Back to top
GuestUsr
Guest





PostPosted: Sun Mar 21, 2010 6:56 pm    Post subject: Reply with quote

and it does not work any program other than notepad.
Like in firefox
Back to top
GuestUsr
Guest





PostPosted: Mon Mar 22, 2010 1:04 pm    Post subject: get it work on other programs Reply with quote

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 ?
Back to top
GuestUsr
Guest





PostPosted: Wed Mar 24, 2010 9:18 am    Post subject: got it Reply with quote

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
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group