 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
SegPhault Guest
|
Posted: Tue Jun 08, 2004 2:23 am Post subject: Loop, Windows |
|
|
AHK is an awsome utility, truly the best macro system for windows i've ever encountered. There are a few things I'd like to be able to do that I cannot. Windows would be a bit more tolerable if I could do window packing from the keyboard.
I first encountered the concept of packing while using Sawfish, a window manager for XWindows that was written in lisp. Packing allows me to move a window in a certain direction until the edge of the window touchs the edge of the screen, or the edge of another window.
In order to do this, I need to be able to iterate through each window on the desktop and acquire all of their edges and positions. I have not found a way to do this. I would like a "Loop, Windows" command to remedy this situation.
Even if I am able to loop through windows, storing an arbitrary number of variables might prove difficult. It would be nice if I could have array variables, something along the lines of python's lists.
Ultimately, it may be easier to simply write an external program that calculates the position to move the window to and returns the values to the AHK script. If anyone has done anything like that, i'd appreciate some advice or suggestions.
Along that line of reasoning, it would be neat if there was an SDK or standard extension mechanism that would allow programmers to add syntax and functionality to AHK. I realize that something of that nature would probably be incredibly difficult to implement, but it would definitely be worthwhile. It would also be REALLY cool if I could generate DLLs from AHK scripts, and call script subroutines from Delphi programs or something like that.
Keep up the great work!  |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Tue Jun 08, 2004 5:15 am Post subject: |
|
|
Thanks for your feedback. What you've said is definitely thought-provoking.
| Quote: | | Even if I am able to loop through windows, storing an arbitrary number of variables might prove difficult. It would be nice if I could have array variables, something along the lines of python's lists. |
You can do arrays, even multi-dimensional, though not as easy as in a language that has native support for arrays. Dynamic variables (as you said, an arbitrary number) are also possible. This touches on the subject: http://www.autohotkey.com/docs/misc/Arrays.htm
| Quote: | | I need to be able to iterate through each window on the desktop and acquire all of their edges and positions. I have not found a way to do this. I would like a "Loop, Windows" command to remedy this situation. |
I think you might be able to achieve some of this by using an example similar to the one in the help file:
| Code: | ; This example will visit all open windows and display info
; about each of them:
WinGet, id, list, , , Program Manager
Loop, %id%
{
StringTrimRight, this_id, id%a_index%, 0
WinActivate, ahk_id %this_id%
WinGetClass, this_class, ahk_id %this_id%
WinGetTitle, this_title, ahk_id %this_id%
MsgBox, 4, , Visiting All Windows`n%a_index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n`nContinue?
IfMsgBox, NO, break
} |
It might also be of interest that MouseGetPos can tell you which window the mouse cursor is currently hovering over. By combining the above with WinGetPos and WinMove, you might be able to do what you want. |
|
| Back to top |
|
 |
SegPhault Guest
|
Posted: Tue Jun 08, 2004 12:16 pm Post subject: success! |
|
|
| Thanks for the code sample. Looks like the scripting language is a bit more comprehensive than I initially thought. I'll have to spend some more time looking through the documentation. In any event, I was able to implement window packing. The subroutines are lengthy, so rather than posting it here, I uploaded the script to my web site. Here is a link, for anybody who is interested: http://mmearth.net/gaerdin/code/scripts/winpack.ahk |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Tue Jun 08, 2004 4:30 pm Post subject: |
|
|
Looks good. Since it's not readily clear to me how to put it into action, perhaps you can add some sample hotkey definitions at the top for demonstration purposes? For example:
; Here is where you define your hotkeys.
; Change them according to your preferences.
Hotkey, #z, MyLabel
...
return ; end of autoexecute section
...
(and down here are all the subroutines)
| Quote: | | For some reason, when I include this script in an existing script and use the subroutines, it usually doesnt work, or behaves badly |
This is probably because you're including it in the auto-execute section (top part) of another script. The #include directly puts the contents of the included file physically in the exact spot where the #include is encountered. If you think there's a bug with the #include directive, please let me know. |
|
| Back to top |
|
 |
Beastmaster
Joined: 15 Apr 2004 Posts: 182
|
Posted: Tue Jun 08, 2004 7:24 pm Post subject: |
|
|
allSnap
allSnap is a small system tray app that makes all top level windows automatically align like they do in programs such as Winamp or Photoshop.
[Download]
FreeSnap
Ever try to size a window so it just touches the edge of the screen? It's tedious (at least for me). FreeSnap allows you to instantly size any window edge to the corresponding screen edge. Want that window to touch the right edge of the screen? Press and hold the windows key and press the right arrow. It's just that simple. The number-pad keys work as well, regardless of the NumLock state.
[Download] |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Jun 11, 2004 4:24 pm Post subject: |
|
|
[quote="cmallett"] Since it's not readily clear to me how to put it into action, perhaps you can add some sample hotkey definitions at the top for demonstration purposes?
I didnt want to clutter it up with my funky keybinding prefs. I'm a vim fan, so I tend to like vim style directional bindings:
; Window Packing
#+h::GoSub, PackLeft
#+l::GoSub, PackRight
#+j::GoSub, PackBottom
#+k::GoSub, PackTop
; Window Sizing
#^!l::GoSub, SizeRight
#^!h::GoSub, SizeLeft
#^!j::GoSub, SizeDown
#^!k::GoSub, SizeUp |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Fri Jun 11, 2004 5:11 pm Post subject: |
|
|
I tried it. I think my problem is that I don't understand what window packing is. Since your enumerating all windows in the system, it's obvious it has something to do with the active window's relationship with all the other windows around it.
Before I forget, the script might be enhanced a little by adding the following lines at the top:
#SingleInstance ; Prevents more than one instance of this script.
SetBatchLines 10ms ; Makes it run faster.
SetWinDelay, 10 ; Optional: makes windowing commands faster.
The below are some further comments that are probably just due to my lack of knowledge about window packing:
Although PackLeft and PackTop work on a sample window (Notepad in this case), their opposites move the window entirely off the screen on my system. Maybe that's intentional.
Similarly, SizeLeft/Up make the window extend all the way to the left/top edges of the screen, but SizeRight/Down cause the window to shrink to minimum width/height rather than expanding toward the right/bottom edges of the screen as I would expect.
Thanks,
Chris |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|