Jump to content

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

[AHK_L] *Fast* Word Lookup (Without Browser)


  • Please log in to reply
7 replies to this topic
Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

I use this in a tooltip-like GUI, but here's an example of using it with a Tooltip

 

Update: here's a slightly modified version using CFlyout:

Spoiler

 

Example.ahk

Spoiler

 

Spoiler


Edited by Verdlin, 09 September 2013 - 02:07 PM.

Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009

I added these lines to the top of your listing (using AHK_L) 

 

inputbox, sWord
msgbox % DictLookup(sWord)
return
 

I tried "dog".

It doesn't seem to work for me. The msgbox is empty.

 

Perhaps you could give a sample script and an example word ??



Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Certainly! My apologies. There is a comment in my script that says the function returns a 2-element array, but, perhaps, I should've clarified this in my original post. I chose to use an array solely because it made it easy to separate the definition from the synonyms -- sometimes you'll want only the definition.

 

This line works, for me:

Msgbox % DictLookup("Dog")[1]

Also, here is one example that is similar to how I use it:

Spoiler


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009

Thanks for "this line"

 

I missed reading that an array is returned. And I am also unskooled in the new AHK_L form of arrays.

 

Here is an example that is more friendly to me.

 

return ; end autoexecute section
 
f1::
inputbox, sWord, Definition, Enter a word to receive the definition and Synonyms
if !ErrorLevel
{  
  result := DictLookup(sWord)
  msgbox % "word: " sword "`r`n`r`n" result[1] "`r`n`r`nSynonyms`r`n" result[2]
}
else
  msgbox operation cancelled.
return


 

To make clipwait work correctly, the clipboard need to start empty

here are a few changes I suggest to QuickDef

    clipboard =
    SendInput ^{c}
    clipwait,2
 
    if errorlevel
    {
      msgbox no data found
      return
    }
;    Sleep (50) ; ClipWait doesn't seem to be working here, so sleep.

 

I noticed that the response may not be immediate.

I suggest adding the tooltip once before the "while loop" so that the user gets an answer even if they don't press & hold ^+space::

And you might look at the example for "mousegetpos" that uses settimer (instead of the while loop)

 

Btw, what is the operation difference bwtween these two hotkeys ?

 

~^~+~Space::    ;<-------- your version

 

 ^+space::         ; <-------- my version



Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Thanks for the suggestions. I implemented your changes using Clipwait, and everything is still working well. My older problem must have been from not clearing out the clipboard. I also added some status output immediately upon triggering the hotkey. Lastly, The use of ~^~+~Space was, simply, old script leftover from another way I used to accomplish this. See below:

 

Spoiler

 

As I implied before, I do not use this in an actual Tooltip. If anyone does, you probably will want to use a word-wrapping function because the synonym list can easily span the whole width of the screen, otherwise. Msgbox is a great alternative since it automatically wraps the text, but I prefer a less intrusive window.

 

Concerning timers vs. while loop, I am familiar with the example in MouseGetPos (although I looked at it again, just to be sure). I used to use timers for things such as this, but, because of the way I use AHK, I typically try to be sparing with my timers. I don't know how most people use AHK, but I load up all sorts of huge projects into the Autohotkey.exe. This really hasn't been a problem, except for when using timers. I used to have so many different timers running that they would halt/collide with each other. Some of this was due to bad scripting (such as using Process, Wait in a timer). Still, whenever I want to add another timer, I have to be completely aware of what my other timers are doing so that I don't interfere with them. It seems easier, for me, to implement alternative methods, instead.


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Update: thesaurus.com changed a few things, so the original script broke. I just provided a new one which includes features such as:

  • Nice formatting
  • If no entry was found for selected word, then the script retries using a suggested word strait from thesaurus.com. It will also indicate in the output that the original word was not found and show the definition of the suggested word.

Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

thesaurus.com changed again. Updated script to new html


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

thesaurus.com changed again. Updated script to new html...I probably need to find another website. The format for the HTML keeps bouncing back between two different versions every two weeks or so.


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.