Jump to content

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

Mouse-driven Encarta dictionary lookup


  • Please log in to reply
2 replies to this topic
ezuk
  • Members
  • 149 posts
  • Last active: Jan 02 2013 08:54 AM
  • Joined: 04 Jun 2005
Hi all,

Sometimes I read webpages or e-books without having my keyboard on me (I don't have a proper desk). If I have a word I want to look up in a dictionary (and this happens quite often as I like to understand every word I read), I need to do acrobatics with the keyboard and type it in and then put the keyboard away again. Not comfortable, and not necessary when you have AHK.

So, I threw together a small script to do this using the mouse. You highlight a word (by double-clicking it) and then middle-click the mouse to look it up in Encarta. This is meant to be running only while you're reading a long document without a keyboard, of course.

I assume this might have already been done, and most probably more elegantly and generically than in my implemention... But anyway, this is my quick little hack for it.

The "IfInString" just checks for a space in the end of the word, because some programs select the trailing space as a part of the word (like Firefox, for instance).

What it does:

1) You double-click the word to mark it
2) Middle-click to look it up
3) Scroll up and down with the mousewheel as usual
4) To flip one defintion backwards in the glossary, press RButton and scroll up. The move one def forward, Rbutton and scroll down
5) To return the mouse to its original position, middle-click again while in the Encarta window.

The mouse wouldn't really return the the exact original position (I have no idea why -- does anyone know? ) but it will be pretty close. It also won't really activate the original window with the click -- I'm not sure why.

Another small quirk is that on my LiteStep system, whenever I get out of the defined workarea for the desktop, the script fires. Really weird. Like it catches an MButton click -- but there's no click, just a mouse move to some off-screen coords. Weird.

Anyway, this is it:

MButton::
IfWinActive,Microsoft Encarta World English Dictionary
	{
	CoordMode,Mouse,Screen
	MouseClick,Left,StartMouseX,StartMouseY,4,0
	}		


IfWinNotActive, Microsoft Encarta World English Dictionary
{
	MouseGetPos,StartMouseX,StartMouseY,StartMouseWin
	send,^c
	if %clipboard% 
	{
		StringRight,EndOfString,clipboard,1
		PunctString = " .,!'
		IfInString,EndOfString,%A_Space%
		{
		StringTrimRight,clipboard,clipboard,1
		}
		winactivate,Microsoft Encarta World English Dictionary
		send,!f^v{ENTER}
		MouseMove,300,300
	} 
}
return
 
~RButton & WheelUp::
	IfWinActive,Microsoft Encarta World English Dictionary
	{
	Controlclick,bsbtn1,A,,,2
	}
	return
	
~RButton & WheelDown::
	IfWinActive,Microsoft Encarta World English Dictionary
	{
	controlclick,bsbtn2,A
	}
	return



delta
  • Members
  • 44 posts
  • Last active: Sep 14 2005 08:46 AM
  • Joined: 16 Feb 2005
Nice idea. I think you can minimize the mouse clicks even more and use a fragment like this:
MButton::
  temp = %clipboard%
  clipboard =
  Send, ^c
  If clipboard =
  {
    MouseClick, Left,,, 2
    Send, ^c
  }
  clipboard = %temp%
So if something is already selected then just use this, otherwise send a double click which will select the word under the mouse pointer and grab it.

The mouse wouldn't really return the the exact original position (I have no idea why -- does anyone know? ) but it will be pretty close. It also won't really activate the original window with the click -- I'm not sure why.

That's because you grab the mouse coordinates in default coord mode (that's "relative") and set the coord mode to "screen" before you move the mouse pointer back. I suggest you grab the window title before you switch to Encarta (WinGet or WinGetTitle). Then you can let a middle click (while Encarta is active) change back to the original window and use the relative mouse coordinates you grabbed before to restore the mouse. (It's saver too, because clicking at the original coordinates might not reactive the orignal window if it is (partly) covered by another window, i.e. Encarta) But if you do it this way, be sure to include a "return" in the first if block to leave the script. Otherwise the second If-condition will be true right away again and you will end up in Encarta.

Oh, last thing, to test whether the clipboard is empty use
If clipboard =


ezuk
  • Members
  • 149 posts
  • Last active: Jan 02 2013 08:54 AM
  • Joined: 04 Jun 2005

Nice idea. I think you can minimize the mouse clicks even more and use a fragment like this:


Wow, thanks for the great comment! :) I will probably use these ideas.