AutoHotkey Community

It is currently May 26th, 2012, 3:38 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 63 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject:
PostPosted: March 18th, 2009, 12:58 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Yes, I'm using 1.0.48.00.

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2009, 4:42 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Sorry for subsequent posting. Here's an updated version of the script with added multi-monitor detection and a bit of clean-up. Hope you don't mind:
Code:
; http://www.autohotkey.com/forum/viewtopic.php?t=42005
; Look up anywhere
; by keyboardfreak
; v1.2 (modded by Drugwash)
;________________________________________________
;________________ DECLARATIONS __________________
#NoEnv
delay_to_hide = 10
gui_width = 500
gui_height = 300
browser_margin = 5
hide_distance = 50
dummytext := "some dummy text"
gui_id =
gui_title := "quick info lookup"
sources_num = 0
current_source = 1
;________________________________________________
;__________________ AUTOEXEC ____________________
add_source("Wikipedia", "http://en.wikipedia.org/wiki/Special:Search?search=", "document.getElementById('column-one').style.display='none';document.getElementById('content').style.marginLeft=0")

add_source("Google Define", "http://www.google.com/search?ie=utf-8&oe=utf-8&hl=en&q=define:", "document.getElementById('header').style.display='none';document.getElementById('tsf').style.display='none';document.getElementById('ssb').style.display='none'")

add_source("IMDb", "http://www.imdb.com/find?s=all&q=", "document.getElementById('nb15').style.display='none'")

add_source("Leo.de", "http://dict.leo.org/ende?lp=ende&lang=de&searchLoc=0&cmpType=relaxed&search=", "document.getElementById('mainnavigation').style.display='none';document.getElementById('searchrow').style.display='none';document.getElementById('header').style.display='none';if(document.getElementById('subnavigation')){document.getElementById('subnavigation').style.display='none';}var tds=document.getElementsByTagName('td');for (var i = 0; i < tds.length; i++)if(tds[i].className == 'sidebar') tds[i].style.display='none'")

Gui, +LastFound  -SysMenu +Owner
Gui, Color, 66CCFF
Gui, Add, Text, section, Text:
Gui, Add, Edit, ys vText gTextChanged

list =
Loop, %sources_num%
   {
   name := sources%a_index%_name
   if (list == "")
      list = %name%
   else
      list = %list%|%name%
   }

Gui, Add, DropDownList, ys Choose%current_source% vSource gSourceChanged, %list%
Gui, Add, Button, ys gpopout, &Pop out
Return
;________________________________________________
;___________________ HOTKEYS ____________________
$esc::
  if gui_visible
   gosub guihide
  else
   send {esc}
Return

pause::
F7::
  oldclipboard := clipboard
  clipboard := dummytext
  SendInput ^c
  Sleep, 500 
  expression := clipboard
  clipboard := oldclipboard
  if (expression == dummytext)
   expression :=

  PosGui(gui_width, gui_height)               ; call the active monitor detection function
  Gui, Show, x%gui_x% y%gui_y% w%gui_width% h%gui_height% , %gui_title%
  DllCall("SetCursorPos", int, gui_cx, int, gui_cy)   ; this works better in multi-monitor environments (MouseMove fails)

  GuiControl, Focus, Text
  GuiControl,,Text, %expression%
  SendInput {end}

  if (expression <> "")
   GuiControl, Focus, Source

  if (gui_id == "")
   {
   top_margin = 30
   IE_Init()
   gui_id := WinExist(gui_title)
   pweb := IE_Add(gui_id, browser_margin, browser_margin + top_margin, gui_width - (2 * browser_margin), gui_height - (2 * browser_margin) - top_margin)
   }

  if (expression <> "")
   load_url()

  SetTimer, hidegui, %delay_to_hide%
  gui_visible := true
Return

;________________________________________________
;_________________ SUBROUTINES __________________
hidegui:
  MouseGetPos x, y
  if (x < -hide_distance or x > (gui_width  + hide_distance) or y < -hide_distance or y > (gui_height + hide_distance))
   gosub guihide
Return

textchanged:
  SetTimer, textchanged_idle, 500
Return

textchanged_idle:
  SetTimer, textchanged_idle, off
  GuiControlGet, expression,,text
  if (expression <> "")
   load_url()
Return

wait_for_page_load:
  if (IE_ReadyState(pweb) == 4)
   {
   SetTimer, wait_for_page_load, off
   COM_Invoke(pweb, "document.parentwindow.execscript", "try{" . sources%current_source%_pagefix . "}catch(e){}")
   }
Return

guihide:
  Gui, Hide
  gui_visible := false
  SetTimer, hidegui, off
  SetTimer, wait_for_page_load, off
Return

GuiClose:
  COM_Release(pweb)
  Gui, Destroy
  IE_Term()
Return

SourceChanged:
  SetTimer, sourcechanged_idle, 500
Return

SourceChanged_idle:
  SetTimer, sourcechanged_idle, off
  GuiControlGet, source_name, , source
  Loop, %sources_num%
   {
   if (source_name == sources%a_index%_name)
      {
      current_source := a_index
      break
      }
   }
  load_url()
Return

popout:
  gosub guihide
  Run % IE_GetUrl(pweb)
Return

;________________________________________________
;__________________ FUNCTIONS ___________________
add_source(name, url, pagefix = "")
{
  global
  sources_num++
  sources%sources_num%_name := name
  sources%sources_num%_url := url
  sources%sources_num%_pagefix := pagefix
}

get_url()
{
  global
  Return sources%current_source%_url . expression
}

load_url()
{
  global
  IE_LoadURL(pweb, get_url())
  if (sources%current_source%_pagefix <> "")
   SetTimer, wait_for_page_load, 100
  else
   SetTimer, wait_for_page_load, off
}

;________________________________________________
;___________ MULTI-MONITOR DETECTION ____________
PosGui(GW, GH)            ; pass GUI size as parameters
{
  Global gui_x, gui_y, gui_cx, gui_cy   ; top-left corner and center of the GUI (the latter is used for positioning the mouse)
  WinGetPos, AX, AY, AW, AH, A   ; get active window coordinates
  AcenH := AX + AW//2         ; get active window horizontal center
  AcenV := AY + AH//2         ; get active window vertical center
  SysGet, Tmon, 80            ; find total number of monitors
  Loop, %Tmon%
   {
   SysGet, Mon%A_Index%, MonitorWorkArea, %A_Index%                              ; get working area for monitor %A_Index%
   Mcen%A_Index%H := Mon%A_Index%Left + (Mon%A_Index%Right - Mon%A_Index%Left) // 2      ; get monitor horizontal center
   Mcen%A_Index%V := Mon%A_Index%Top + (Mon%A_Index%Bottom - Mon%A_Index%Top) // 2   ; get monitor vertical center
   if (AcenH <= Mon%A_Index%Right && AcenH >= Mon%A_Index%Left)
      {
      gui_x := Mcen%A_Index%H - GW//2
      gui_y := Mcen%A_Index%V - GH//2
      gui_cx := gui_x + GW//2
      gui_cy := gui_y + GH//2
      break
      }
   }
}

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2009, 4:59 pm 
Online
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Wow, what a wide code... Could you use continuation sections to improve the readability of your code, please?

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2009, 5:27 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Well, I didn't mess with the COM and IE functions... ;)

Oh and I accidentally forgot to comment out the F7 hotkey; that's just for my personal convenience and might disturb others' activity, so it may safely be removed.

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2009, 9:41 pm 
Offline

Joined: October 9th, 2004, 8:55 pm
Posts: 217
Location: Budapest, Hungary
Drugwash wrote:
Sorry for subsequent posting. Here's an updated version of the script with added multi-monitor detection and a bit of clean-up. Hope you don't mind


Nope, but I believe in gradual improvement, so I didn't apply all your changes. I did some cleanup, though, and made some of the long lines less longer.

I tested the script with the latest Autohotkey, but it works fine for me without the added sleep. Nevertheless, I added a config variable sleep_after_copy with a default value of 0. You can set it to a value which is appropriate for you.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 12:49 am 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Everything's fine as long as it works. ;) Just a remark: SysGet, Screen, Monitor is not used anymore, it can go.

And IMHO it would be good to keep a versioning of some sort, might help people when checking for updates.

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 4:13 pm 
Offline

Joined: March 19th, 2009, 4:04 pm
Posts: 9
Really nice work.

The only thing: I experience some problem similar to soggydogs problem, I think. When I hit "Pause" it does not paste the selected text automatically. I have to do it by myself, for example by pushing ctrl+v. Then it looks up the pasted selection. I'll take a further look at it, but I'm still a beginner in ahk.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 4:33 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
@gregster

The mods by Drugwash don't seem to exhibit this behavior;
You might try his mods before debugging the version you're currently running.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 4:40 pm 
Offline

Joined: March 19th, 2009, 4:04 pm
Posts: 9
Thank you very much, soggy dog. You are right. drugwashs version solved my problem.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 7:18 pm 
Offline

Joined: October 9th, 2004, 8:55 pm
Posts: 217
Location: Budapest, Hungary
SoggyDog wrote:
The mods by Drugwash don't seem to exhibit this behavior;


The current version is essentially the same as Drugwash's version, you only need to set the sleep_after_copy variable, so it should work too.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 8:37 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
keyboardfreak wrote:
SoggyDog wrote:
The mods by Drugwash don't seem to exhibit this behavior;

The current version is essentially the same as Drugwash's version, you only need to set the sleep_after_copy variable, so it should work too.

As Drugwash suggested earlier, you might consider "versioning" your code to avoid this type of confusion in the future.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 8:41 pm 
Offline

Joined: October 9th, 2004, 8:55 pm
Posts: 217
Location: Budapest, Hungary
SoggyDog wrote:
As Drugwash suggested earlier, you might consider "versioning" your code to avoid this type of confusion in the future.


Every time I edit the script in the first post the "Last edited" indicator below the post is updated automatically. Also I always write about the updates in a new post.

So it's not that hard to notice if a new version is posted. Nevertheless, I'll add versioning info next time the code is updated to make it even more explicit.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 8:50 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
keyboardfreak wrote:
Every time I edit the script in the first post the "Last edited" indicator below the post is updated automatically. Also I always write about the updates in a new post.

So it's not that hard to notice if a new version is posted. Nevertheless, I'll add versioning info next time the code is updated to make it even more explicit.

a) Every time you edit ANYTHING on the post it changes the indicator, so that's unreliable.

b) Not everyone re-reads posts; It's already been read once, right?

c) Thank you.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 8:56 pm 
Offline

Joined: October 9th, 2004, 8:55 pm
Posts: 217
Location: Budapest, Hungary
SoggyDog wrote:
Not everyone re-reads posts; It's already been read once, right?


Yep, that's why I also write a new post every time I update something. I assume they read at least the new posts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 9:00 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
keyboardfreak wrote:
SoggyDog wrote:
Not everyone re-reads posts; It's already been read once, right?

Yep, that's why I also write a new post every time I update something. I assume they read at least the new posts.

I would have to agree with that;
Versioning, in general, is still good form though.

Peace.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 63 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 17 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