AutoHotkey Community

It is currently May 27th, 2012, 12:06 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: December 8th, 2005, 12:32 pm 
Offline

Joined: December 8th, 2005, 12:30 pm
Posts: 9
Hi,

I want to be able to send often used strings to various applications. I don't want to use a keyboard shortcut but use the tray menu.

I have extended the ahk tray menu with some menu items, however, how do I activate that window that was active before I clicked on the tray icon?
I don't think that WinActivate ca help me, because I don't have a specific window name, it could be whatever windows I want.

e.g. I have the cursor in a web form in my browser and want to enter some often used text (e.g. my name), so I want to right click the H in the tray and select "Insert Name", then my script should my name to the last cursor position.

Oliver

_________________
Oliver Kötter


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2005, 1:56 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Since it should be the last active window you should find it with WinGet,List, please see http://www.autohotkey.com/forum/viewtopic.php?t=4810 for more code snippets

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2005, 3:14 pm 
Offline

Joined: December 8th, 2005, 12:30 pm
Posts: 9
Thanks, that helped me a lot.
Unfortunately e.g. in a browser formular the cursor is not in the same field as before, so I made a workaround this way: the script waits for a left mouse click, this way I can set the cursor with a left mouse click to the right form field.

Code:
#Persistent
#SingleInstance
menu, tray, add ; separator
menu, tray, add, Write EMail Address, email
return

email:
  WinGet, WindowList, List
  List =
  Loop %WindowList%
  {
    WinUID := WindowList%A_Index%
    WinGetTitle, WinTitle, ahk_id %WinUID%
    If WinTitle <>
      Break
  }
  WinActivate, ahk_id %WinUID%
  KeyWait, Lbutton , D T60
  if ErrorLevel=0 ; clicked
    Send, my@email.address
return



Hey, that's my first real script and I'm proud of it ;-)

Thanks again for your help!

_________________
Oliver Kötter


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2005, 11:13 am 
Offline

Joined: December 8th, 2005, 12:30 pm
Posts: 9
Quote:
Code:
  WinGet, WindowList, List
  List =
  Loop %WindowList%
  {
    WinUID := WindowList%A_Index%
    WinGetTitle, WinTitle, ahk_id %WinUID%
    If WinTitle <>
      Break
  }
  WinActivate, ahk_id %WinUID%


Is this looping though the Windows also possible for the controls?
I want to put the cursor in the last active field again...

Thanks,

Oliver

_________________
Oliver Kötter


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2005, 2:02 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Instead of using the tray icon, you could use a RButton Menu. So the control doesn't loose its focus (or you can reactivate it with a mouse click at the same location you right clicked) and sending is easier.

Rajat made a script for this
http://www.autohotkey.com/forum/viewtopic.php?t=233

It might be more complex then you need it.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2005, 2:08 pm 
Offline

Joined: December 8th, 2005, 12:30 pm
Posts: 9
Quote:
Instead of using the tray icon, you could use a RButton Menu.


No, because I do not want to send strings to a special application but I want to be able to send to ANY app, including apps that has context menues so I don't want to bind to the right mouse button.

Oliver

_________________
Oliver Kötter


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2005, 2:12 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
You could use any hotkey you like to pop up the menu. It is just an idea, that will solve your problem.
I doubt that you can get a list of last active controls. Specially from a browser. So there will be no option to loop through them.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2005, 3:38 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
This is the simplest solution
http://www.autohotkey.com/forum/viewtopic.php?p=40665

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2005, 3:46 pm 
Offline

Joined: December 8th, 2005, 12:30 pm
Posts: 9
Wow.... thanks a lot! I must say... outstanding support in this forum! I begin to like AutoHotKey....

_________________
Oliver Kötter


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2005, 12:33 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
The following code demonstrates sending text to the last active window and control:

Code:
WM_USER = 0x400
AHK_NOTIFYICON := WM_USER+4
OnMessage( AHK_NOTIFYICON, "HandleMessage" )

Menu, Tray, NoStandard
Menu, Tray, Add, Insert Name, InsertName
Menu, Tray, Add
Menu, Tray, Standard
return

HandleMessage( p_w, p_l )
{
   global   hw_last_active, control_last_active, hold_last_active

   ; WM_MOUSEMOVE
   if ( p_l = 0x200 and ! hold_last_active )
   {
      WinGet, hw_last_active, ID, A
      ControlGetFocus, control_last_active, ahk_id %hw_last_active%
   }
   ; WM_RBUTTONDOWN
   else if ( p_l = 0x204 )
   {
      hold_last_active := true
   }
}

InsertName:
   ControlSendRaw, %control_last_active%, Oliver Kötter, ahk_id %hw_last_active%
   
   hold_last_active := false
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2005, 3:06 pm 
Offline

Joined: December 8th, 2005, 12:30 pm
Posts: 9
How would this script look like if I did not use the tray icon but a user generated menu on the Win-Q key?

Code:
menu, SubMenuTexts, add, &Login x, LoginX
menu, SubMenuTexts, add, &Passwort Y, PassWdY

Menu, Ollie, add, Texte, :SubMenuTexts
menu, Ollie, add, other Stuff, otherStuff
menu, Ollie, add
menu, Ollie, add, Open in ... , OpenIn

; Hotkeys:

; Windows-Q für Quickmenu
#q:: menu Ollie, Show


I guess I don't need the OnMessage because I can handle the ControlGetFocus before the "menu Ollie, Show" so that the control does not lose focus before the ControlGetFocus, but then I don't have the p_w and the p_l parameters...

_________________
Oliver Kötter


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2005, 3:57 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
owilsky wrote:
I don't need the OnMessage... the control does not lose focus
...
I don't have the p_w and the p_l parameters


Exactly. Review the syntax for WinGet and ControlGetFocus to understand the meaning of each parameter.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, Google [Bot], Yahoo [Bot] 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