Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Tool tip dictionary


  • Please log in to reply
27 replies to this topic
delta
  • Members
  • 44 posts
  • Last active: Sep 14 2005 08:46 AM
  • Joined: 16 Feb 2005
There are some scripts around that automatically look up words on dictionary sites. I've always been reluctant to use those because I don't like it if the site I'm viewing is covered by another site. Nevertheless a dictionary is quite useful, so I tried my own script which uses (more or less) small tooltips.

It uses the site lookwayup.com because the entries there are quite short (good for tool tips without much formatting). Another reason is, that it has also Spanish, French and Portuguese dictionaries, which are now easier to include (but they need some more formatting though)

The script works as follows: Highlight a word or a phrase and click the middle mouse button. The last tool tip will vanish if you move the mouse a little (how much is specified in the variable mousetol, see comments in the script)

However, it is not perfect. Apart from cosmetic issues (tooltips are sometimes very wide, script could be improved (2 times GoTo! :shock: )) there is one thing: if there is too much data you can left click and see the next tool tip. Ideally that would be again the middle mouse button, but this is one locked, since it is the hotkey already. Moreover the left-click is passed through which is sometimes not desirable (e.g. if you marked a link)

Other than this the script works great for me. Comments welcome.

; _______________________________________________________
;
;    Usage: Highlight a word or a phrase and press
;           the middle mouse button to display a
;           translation retrieved from:
;                http://lookwayup.com/
;
; _______________________________________________________

#UseHook

; _______________________________________________________
;
;    mousetol:  The final tool tip will vanish if
;               the mouse is moved more then %moustol%
;               pixels away from the current position
; _______________________________________________________

mousetol = 3;

; _______________________________________________________
;
;    Some variables to shorten the scripts somewhat:
;       wordtypeshort: the letters used by lookwayup
;                      to mark certain wordtypes
;       wordtypelong : what the letters actual mean
;       typecount    : how many types do we have?
;
;    Note: If there should be types I have forgotten
;          the script will pop up a message box
;          displaying the missing letter. It can be
;          easily included in wordtypeshort and
;          wordtypelong.
; _______________________________________________________

wordtypeshort = vnarpocd
wordtypelong = verb|noun|adjective|adverb|preposition|pronoun|conjunction|determiner

tempfile = tooltipdic.ttd

StringLen, typecount, wordtypeshort

; _______________________________________________________
;
;    Variables to refine HTML Unicode which occurs
;    sometimes. If you should come about more than
;    those you can add them here.
; _______________________________________________________

replace = "|'
substitute = "'

offset = 0

return



; _______________________________________________________
; 
;    Actual script start here
; _______________________________________________________

MButton::
   Begin:
   d =
   If offset = 0
   {
      temp = %clipboard%
      clipboard =
      Send, ^c

      If clipboard =
      {
         clipboard = %temp%
         temp =
         return
      }
      Else
      {
        lookup = %clipboard%
        clipboard = %temp%
        temp =
      }   
      ToolTip, Retrieving information on "%lookup%"...
   }
   Else
   {
      ToolTip, Retrieving more information on "%lookup%"...
      d = &d=%offset%
   }

   ; _______________________________________________________
   ;
   ;    Fetch dictionary entry
   ; _______________________________________________________

   FileDelete, %tempfile%
   URLDownloadToFile, http://lookwayup.com/lwu.exe//lwu/d?w=%lookup%%d%, %tempfile%
   
   IfNotExist, %tempfile%
   {
      ToolTip, Sorry`, connection timed out.`nTry again later.
      MouseGetPos, X, Y
      GoTo, ToolTipDelete
   }
   
   entry = 0
   more = 0
   
   ; _______________________________________________________
   ; 
   ;    Prepare strings for different word types
   ; _______________________________________________________

   Loop, parse, wordtypelong, |
   {
      StringMid, type, wordtypeshort, %A_Index%, 1
      %type%_entry = %A_LoopField%`n
      If offset = 0
         %type%_count = 0
      %type%_found = 0
   }
   
   wordfound = yes
   Loop, Read, %tempfile%
   {
      IfInString, A_LoopReadLine, <h4>
      {
         StringTrimLeft, displayed, A_LoopReadLine, 4
         StringGetPos, trim, displayed, </h4>
         StringLeft, displayed, displayed, trim
         If offset > 0
            displayed = %displayed%%A_Space%(continued)
      }
      IfInString, A_LoopReadLine, colspan=2
         entry = 0
      IfInString, A_LoopReadLine, not found
         {
            wordfound = no
            break
         }
      If entry = 1
      {
         line = %A_LoopReadLine%
         IfNotEqual, line,
         {
            IfInString, line, VALIGN
            {
               StringRight, type, line, 2
               StringLeft, type, type, 1
               IfNotInString, wordtypeshort, %type%
                  MsgBox, Unsupported type (%type%) discovered!
            }  
            Else
            {
               StringGetPos, trim, line, <A HREF
               tofetch := trim - 1
               StringLeft, def, line, tofetch
               ++%type%_count
               %type%_found = 1
               temp := %type%_entry
               count := %type%_count
               %type%_entry = %temp%%count%.%A_Space%%def%`n
            }
         }
      }
      IfInString, A_LoopReadLine, CELLPADDING=1
         entry = 1
      IfInString, A_LoopReadLine, More senses
         more = 1
   }
   
   MouseGetPos, X, Y

   ; _______________________________________________________
   ;
   ;    Output any word type which was found
   ; _______________________________________________________

   
   full_entry = %displayed%`n
   If wordfound = yes
   {
     Loop, %typecount%
     {
        StringMid, type, wordtypeshort, %A_Index%, 1
        If %type%_found = 1
        {
           refd := refine(%type%_entry)
           full_entry = %full_entry%`n%refd%
        }
     }
     If more = 1
     {
        full_entry = %full_entry%`n>> left click to display more <<
        ++offset
     }
     ToolTip, %full_entry%
   }
   Else
     ToolTip, Sorry`, no match found.
   
   ; _______________________________________________________
   ;  
   ;    Wait for mouse movement to delete ToolTip.
   ;    If there is more to display also detect, if
   ;    the left mouse button is clicked.
   ; _______________________________________________________
  
   ToolTipDelete:
  
   Loop
   {
     MouseGetPos, Xn, Yn
     Sleep, 50
     If (Abs(X - Xn) > mousetol || Abs(Y - Yn) > mousetol)
        break
     If more = 1
     {
        GetKeyState, LB, LButton
        If LB = D
        {
           more = 0
           GoTo Begin                   ; Go back and start it all over again
                                        ; to display the next page
        }
     }  
   }
   offset = 0
   ToolTip
   
return



; _______________________________________________________
;  
;    Replace HTML code with appropriate characters
;    (see beginning of the script for the strings
;     replace and substitute)
; _______________________________________________________

Refine(html)
{
   Global replace
   Global substitute

   Loop, parse, replace, |
   {
      StringMid, subs, substitute, %A_Index%, 1
      StringReplace, html, html, %A_LoopField%, %subs%, 1
   }
   return, html
}


delta
  • Members
  • 44 posts
  • Last active: Sep 14 2005 08:46 AM
  • Joined: 16 Feb 2005
As you might have noticed: the script exits if no text is selected. That's this part:
If clipboard = 
      { 
         clipboard = %temp% 
         temp = 
         return 
      }
To preserve most of the middle button functionality (in Opera it opens a link in a new tab in the background) without using an additional modifier I suggest you put a
Send, {MButton}
right before the return.

(double post because of the longer time delay)

freakkk
  • Members
  • 182 posts
  • Last active: Dec 16 2014 06:23 PM
  • Joined: 29 Jul 2005
delta--
I think this script is absolutely awesome!! Although I don't have to regularly get definitions of words- its definately a good show piece to new scripters.. & a fresh creative idea. I think you should aim to try being able to highlight full sentences-- & utilize google translate to give you on the fly language translations.
Good job :D
I'm a bit disappointed that no one has responded to your post.

webber
  • Members
  • 129 posts
  • Last active: Aug 13 2011 06:45 PM
  • Joined: 25 Aug 2005
This script doesn't seem to work. It only shows an empty tool tip.

Has anyone been able to make this work ?
________
Monaco

garath
  • Members
  • 398 posts
  • Last active: Feb 05 2011 10:31 PM
  • Joined: 24 Mar 2005
Hmm, left-doubleclick will have the efffekt, that you lose the Highlight.
Right-doubleklick will open a menu.
Maybe, it will be better to use a special key, like F12 or something like that, or you use the right-klick, and look afterwards, if there is a rightklick the next second.


Yes, it is working,
replace MButton:: with RButton::
insert MouseClick, right
after Send, ^c


now the skript will dictionary with rightbutton, and you have the menu as usual

webber
  • Members
  • 129 posts
  • Last active: Aug 13 2011 06:45 PM
  • Joined: 25 Aug 2005
I changed the button to right button but the script still does not do anything except show an empty tooltip.

It does not look up the word in the dictionary .
________
Buy Silver Surfer

garath
  • Members
  • 398 posts
  • Last active: Feb 05 2011 10:31 PM
  • Joined: 24 Mar 2005
Try this little skript to test the lookup, maybe, you have an old version of AHK? but version 37 should be ok, don't know, hmm.


InputBox, word , Dictionary, Word to search:
URLDownloadToFile, http://lookwayup.com/lwu.exe//lwu/d?w=%word%, dict.htm
run, dict.htm


webber
  • Members
  • 129 posts
  • Last active: Aug 13 2011 06:45 PM
  • Joined: 25 Aug 2005
running the latest and greatest but the file dict.htm is empty.

:?:
________
Vaporizer affiliates

garath
  • Members
  • 398 posts
  • Last active: Feb 05 2011 10:31 PM
  • Joined: 24 Mar 2005
hmm, is your IExplorer blocked?
Don't know the method of URLDownloadToFile, but I think, you have a problem with your firewall?

from the Helpfile:

Internet Explorer 3 or greater must be installed for this function to work. Firewalls or the presence of multiple network adapters may cause this function to fail. Also, some websites may block such downloads.

The file is obtained from IE cache whenever possible. You might be able to force a (re)download from the Internet by supplying a fake cgi parameter, for example: "http://.../test.exe?fakeParam=42



webber
  • Members
  • 129 posts
  • Last active: Aug 13 2011 06:45 PM
  • Joined: 25 Aug 2005

IE blocked...


I don't think so . Using IE, if I just plug the url into the address bar, it goes through to the site and looks up the specified word.

I have firefox as my default browser, would that be the problem ?
________
Toyota Ar Engine Specifications

garath
  • Members
  • 398 posts
  • Last active: Feb 05 2011 10:31 PM
  • Joined: 24 Mar 2005
sorry, don't know, I think, it uses a part of the IExporer, but I am no expert :?
You can try to download something else, so you can see, if it depends on URLDownloadToFile or the comunication with this special site

freakkk (as guest)
  • Guests
  • Last active:
  • Joined: --
webber-- check & see if autohotkey is blocked by your filewall. zonealarm asked permission the 1st time i ran it. if that doesn't get it working.. try compiling to its own exe and run it...

corey

freakkk (as guest)
  • Guests
  • Last active:
  • Joined: --
ps-- per help file 'Internet Explorer 3 or greater must be installed for this function to work' for URLDownloadToFile. that doesn't mean it has to be your default browser though..

webber
  • Members
  • 129 posts
  • Last active: Aug 13 2011 06:45 PM
  • Joined: 25 Aug 2005
I have it working, it was a proxy problem

thanks for everyone's assistance.
________
Og Kush Marijuana

delta
  • Members
  • 44 posts
  • Last active: Sep 14 2005 08:46 AM
  • Joined: 16 Feb 2005
Thanks for the comments.

@freakkk:
You can already highlight whatever you want and pass it to the script. The script itself does not highlight anything. It will look up whatever is highlighted.

The google "translation" is a nice idea. Sometimes the first page of results is enough. Like a quick shot in the dark. :wink:
But I think if you include a google search it will cut down the simplicity somewhat. I mean I see two versions: Either you have a tool tip google and tool tip dictionary as (more a less) separate scripts, then you have to define hotkeys for each of them and you have to decide for every word if you want it to be looked up in google or in lookwayup and it wouldn't be just middle click anymore.
The other version could be that you just get everything that could be found. But I think that will be too much information to grasp with one quick glance.
But maybe something like this would work: Look up whatever is hightlighted in lookwayup. If something is found then the user wanted a translation (as a rule of thumb) but if nothing is found present a googled search result list.

Hm, but then again, it seems there is not much interest in this script. Even I forgot the thread after no one had replied after some days.