|
Kruskal
|
 |
« on: May 06, 2010, 08:09:41 PM » |
|
You, Skrommel, were kind enough to write a AHK program for me to provide a hotkey to display a little window showing what program owns the window under the cursor. When pushed a second time, the little window goes away. I use it all the time. (Program at end). I tried to modify it to be a simple program, rather than a hotkey by removing this line: !^w:: It sort of works, but the feature of the second call clearing the little window is gone. I don't know the AHK script language at all. Any idea what I did wrong. Thanks -- Vincent PS I wonder why you haven't made this one of your publicly available (or did I miss it). I find it invaluable. Formatted for AutoIt with the GeSHI Syntax Highlighter [ copy or print] ;AutoHotkeys.ahk ;Vincent Kruskal's Hotkeys ;Skrommel @ 2007 ;Kruskal @ 2007 #SingleInstance,Force #NoEnv !^w:: { WinGet,pid,Pid,ahk_id %winid% path:=GetModuleFileNameEx(pid) ToolTipFlag = 1 } { ToolTipFlag = } #q:: SoundPlay,C:\Documents and Settings\Administrator\My Documents\My Sound Effects\silence .wav GetModuleFileNameEx(p_pid) ;by shimanov at www.autohotkey { If A_OSVersion in WIN_95 ,WIN_98 ,WIN_ME { WinGet,name,ProcessName,ahk_id %p_pid% } h_process: =DllCall("OpenProcess","uint",0x10|0x400 ,"int",false,"uint",p_pid ) ; PROCESS_VM_READ=0x0010 PROCESS_QUERY_INFORMATION=0x0400 If (ErrorLevel or h_process =0) name_size=255 VarSetCapacity(name,name_size) result: =DllCall("psapi.dll\GetModuleFileNameExA","uint",h_process ,"uint",0,"str",name ,"uint",name_size ) }
Edit by Skwire: Added code tags.
|
|
|
|
« Last Edit: May 06, 2010, 10:20:16 PM by skwire »
|
Logged
|
|
|
|
|
Target
|
 |
« Reply #1 on: May 06, 2010, 08:39:42 PM » |
|
if you remove the hotkey, how do you fire the script off? i think the answer is to use a delay then to destroy the tooltip (but the above still applies...) note that the code is untested, but I've just omitted the unnecessary lines so it should work as is [ copy or print] ;AutoHotkeys.ahk ;Vincent Kruskal's Hotkeys ;Skrommel @ 2007 ;Kruskal @ 2007 #SingleInstance,Force #NoEnv !^w:: MouseGetPos,x,y,winid,ctrlid WinGet,pid,Pid,ahk_id %winid% path:=GetModuleFileNameEx(pid) ToolTip,%path% Sleep, 2500 ;this introduces a delay (in milliseconds). Change the value to whatever suits ToolTip, Return #q:: SoundPlay,C:\Documents and Settings\Administrator\My Documents\My Sound Effects\silence.wav Return GetModuleFileNameEx(p_pid) ;by shimanov at www.autohotkey { If A_OSVersion in WIN_95,WIN_98,WIN_ME { WinGet,name,ProcessName,ahk_id %p_pid% Return,name } h_process:=DllCall("OpenProcess","uint",0x10|0x400,"int",false,"uint",p_pid) ; PROCESS_VM_READ=0x0010 PROCESS_QUERY_INFORMATION=0x0400 If (ErrorLevel or h_process=0) Return name_size=255 VarSetCapacity(name,name_size) result:=DllCall("psapi.dll\GetModuleFileNameExA","uint",h_process,"uint",0,"str",name,"uint",name_size) DllCall("CloseHandle",h_process) Return,name }
|
|
|
|
|
Logged
|
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
|
|
|
|
Kruskal
|
 |
« Reply #2 on: May 06, 2010, 09:41:46 PM » |
|
if you remove the hotkey, how do you fire the script off?
i think the answer is to use a delay then to destroy the tooltip (but the above still applies...)
note that the code is untested, but I've just omitted the unnecessary lines so it should work as is
[snip] I use PowerPro to issue the EXE compiled from the AHK code. I've been having trouble with some timing problem which reorders my keystrokes when the computer is stressed. I thought switching to just one key grabber might fix it. I can see how the delay would work and it might be OK. But I really prefer the previous behavior. How did the original work wrt making the little window disappear everyother use? Thanks -- Vincent
|
|
|
|
|
Logged
|
|
|
|
|
|
skwire
|
 |
« Reply #3 on: May 06, 2010, 10:26:51 PM » |
|
I tried to modify it to be a simple program What was your expectation after doing this? How did the original work wrt making the little window disappear everyother use? It uses the "ToolTipFlag" variable as a toggle to determine whether to display the display the tooltip or cause it to disappear.
|
|
|
|
|
Logged
|
|
|
|
|
Target
|
 |
« Reply #4 on: May 06, 2010, 10:29:22 PM » |
|
the conditional IF statement determines what happens depending on the value of the tooltipflag variable - IF the variable contains a value, show the tooltip and , ELSE clear the tooltip
the reason it's not working for you without the hotkey (and I'm assuming you're compiling it) is that it resets the flag every time and the code that clears the tooltip is never called
|
|
|
|
|
Logged
|
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
|
|
|
|
Kruskal
|
 |
« Reply #5 on: May 06, 2010, 11:21:27 PM » |
|
I tried to modify it to be a simple program What was your expectation after doing this? I expected that using PowerPro to support the hotkey to call the simple program would behave the same as it had with the AHK hotkey. Thanks -- Vincent
|
|
|
|
|
Logged
|
|
|
|
|
skwire
|
 |
« Reply #6 on: May 06, 2010, 11:24:17 PM » |
|
I expected that using PowerPro to support the hotkey to call the simple program would behave the same as it had with the AHK hotkey. What you want can easily be done with a simple INI settings file to save the toggle setting between application runs. Give me a minute.
|
|
|
|
|
Logged
|
|
|
|
|
Kruskal
|
 |
« Reply #7 on: May 06, 2010, 11:27:13 PM » |
|
the reason it's not working for you without the hotkey (and I'm assuming you're compiling it) is that it resets the flag every time and the code that clears the tooltip is never called
I'd like to understand how variables, such as tooltipflag work, such that it keeps its value over two AHK calls but not over two calls from PowerPro. What is the significance of your (true) assumption that I compiled the code? Would it work as I wanted if I didn't compile it? Thanks -- Vincent
|
|
|
|
|
Logged
|
|
|
|
|
skwire
|
 |
« Reply #8 on: May 06, 2010, 11:36:43 PM » |
|
Actually...if you change it into an executable, the tooltip will disappear almost immediately after starting the script because the script exits immediately. This app could be made to show the tooltip, say, for five seconds and then exit thus making the tooltip disappear on its own. In other words:
1) Run you hotkey to start the app. 2) App displays tooltip for user-specified length of time. 3) App exits and tooltip disappears. There would be no need to run the hotkey a second time to make the tooltip disappear.
Would that work for you?
|
|
|
|
|
Logged
|
|
|
|
|
Kruskal
|
 |
« Reply #9 on: May 06, 2010, 11:43:48 PM » |
|
Actually...if you change it into an executable, the tooltip will disappear almost immediately after starting the script because the script exits immediately. This app could be made to show the tooltip, say, for five seconds and then exit thus making the tooltip disappear on its own. In other words:
1) Run you hotkey to start the app. 2) App displays tooltip for user-specified length of time. 3) App exits and tooltip disappears. There would be no need to run the hotkey a second time to make the tooltip disappear.
Would that work for you?
I'm not at my main computer right now, but I'm pretty sure that you are wrong. The little window showing the window owning program stays displayed after the program exits (as I recall). I could live with the timeout, but I really don't prefer it. I frequently have to do a lot of stuff based on the information and I'd have to write it down. What happened to the INI solution? I was looking forward to details. Thanks -- Vincent
|
|
|
|
|
Logged
|
|
|
|
|
Target
|
 |
« Reply #10 on: May 06, 2010, 11:46:16 PM » |
|
I'd like to understand how variables, such as tooltipflag work, such that it keeps its value over two AHK calls but not over two calls from PowerPro. the original AHK script is persistent, ie it runs and stays resident. Triggering the hotkey fires the routine which assesses the value of the tooltipflag variable and processes accordingly calling the recompiled script from powerpro destroys the previous instance, and the script starts again from scratch - in this case the 'default' action is to display the tooltip, so repeatedly running the script will have no discernable effect What is the significance of your (true) assumption that I compiled the code? Would it work as I wanted if I didn't compile it? no particular significance, it was just my assumption of how you were doing things - ultimately it probably wouldn't make any difference (other than the fact that you need to have AHK installed in order to run an uncompiled script)
|
|
|
|
|
Logged
|
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
|
|
|
|
skwire
|
 |
« Reply #11 on: May 06, 2010, 11:59:19 PM » |
|
I'm not at my main computer right now, but I'm pretty sure that you are wrong. The little window showing the window owning program stays displayed after the program exits (as I recall). It stayed showing because you had a second hotkey (#q::) defined in the script which made the script never exit/end. I could live with the timeout, but I really don't prefer it. I frequently have to do a lot of stuff based on the information and I'd have to write it down. How about displaying it while simultaneous copying the data to your clipboard? What happened to the INI solution? I was looking forward to details. The fact is, without some sort of delay, that type of script will start, run the code, and exit in the blink of an eye. When it exits, it destroys any tooltip created.
|
|
|
|
« Last Edit: May 07, 2010, 12:01:01 AM by skwire »
|
Logged
|
|
|
|
|
Target
|
 |
« Reply #12 on: May 07, 2010, 12:08:59 AM » |
|
further to skwires explanation here's an example that writes to an ini file, but as he says, as soon as the exe...umm... exits, any windows or values are lost [ copy or print] ;AutoHotkeys.ahk ;Vincent Kruskal's Hotkeys ;Skrommel @ 2007 ;Kruskal @ 2007 #SingleInstance,Force #NoEnv iniread, tooltipflag, VKh.ini, flag, status If ToolTipFlag = 0 { MouseGetPos,x,y,winid,ctrlid WinGet,pid,Pid,ahk_id %winid% path:=GetModuleFileNameEx(pid) ToolTip,%path% iniwrite, 1, VKH.ini, flag, status } Else { ToolTip, iniwrite,0, VKH.ini, flag, status } sleep, 5000 exitapp Return #q:: SoundPlay,C:\Documents and Settings\Administrator\My Documents\My Sound Effects\silence.wav Return GetModuleFileNameEx(p_pid) ;by shimanov at www.autohotkey { If A_OSVersion in WIN_95,WIN_98,WIN_ME,WIN_XP { WinGet,name,ProcessName,ahk_id %p_pid% Return,name } h_process:=DllCall("OpenProcess","uint",0x10|0x400,"int",false,"uint",p_pid) ; PROCESS_VM_READ=0x0010 PROCESS_QUERY_INFORMATION=0x0400 If (ErrorLevel or h_process=0) Return name_size=255 VarSetCapacity(name,name_size) result:=DllCall("psapi.dll\GetModuleFileNameExA","uint",h_process,"uint",0,"str",name,"uint",name_size) DllCall("CloseHandle",h_process) Return,name } and the only reason this one works is because there's a short delay at the end to display the tooltip... seems like the original solution might still be the best one for your situation just out of curiosity is there any reason why you couldn't translate the script into powerpro? I suspect this may alleviate a lot of the issues you're experiencing (don't ask me, I don't know the language, but my feeling is that it shouldn't be that hard to do... hehe, famous last words...)
|
|
|
|
|
Logged
|
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
|
|
|
|
Kruskal
|
 |
« Reply #13 on: May 07, 2010, 12:13:04 AM » |
|
I'm not at my main computer right now, but I'm pretty sure that you are wrong. The little window showing the window owning program stays displayed after the program exits (as I recall). It stayed showing because you had a second hotkey (#q:  defined in the script which made the script never exit/end. I was wondering about that. I probably added that at some point. Any idea why I wanted to have a hotkey sound silence???? I could live with the timeout, but I really don't prefer it. I frequently have to do a lot of stuff based on the information and I'd have to write it down. How about displaying it while simultaneous copying the data to your clipboard? Cute idea (if I knew how to do it). But I really don't need a copy of the information -- I need to act on it. What happened to the INI solution? I was looking forward to details. The fact is, without some sort of delay, that type of script will start, run the code, and exit in the blink of an eye. When it exits, it destroys any tooltip created. That's a disappointment. So there is no solution consistent with my preferences? Thanks -- Vincent
|
|
|
|
« Last Edit: May 07, 2010, 12:15:39 AM by Kruskal »
|
Logged
|
|
|
|
|
skwire
|
 |
« Reply #14 on: May 07, 2010, 12:29:11 AM » |
|
That's a disappointment. So there is no solution consistent with my preferences? I could make it display a small GUI window instead of using a tooltip. This way, you could move it out of the way, leave it open as long as necessary, and close it when you're done. Your thoughts?
|
|
|
|
|
Logged
|
|
|
|
|
Kruskal
|
 |
« Reply #15 on: May 07, 2010, 12:35:22 AM » |
|
further to skwires explanation here's an example that writes to an ini file, but as he says, as soon as the exe...umm... exits, any windows or values are lost
[clip]
and the only reason this one works is because there's a short delay at the end to display the tooltip...
seems like the original solution might still be the best one for your situation
just out of curiosity is there any reason why you couldn't translate the script into powerpro? I suspect this may alleviate a lot of the issues you're experiencing (don't ask me, I don't know the language, but my feeling is that it shouldn't be that hard to do... hehe, famous last words...)
What would happen if one instance of the EXE was in its delay when I make the second call to clear the tooltip? If the answer is to my liking, I could make the delay 5 hours, or so, and essentially get the behavior I want. My reason not to write a PowerPro script is that I understand THAT even less than my deplorable knowledge of AHK. Also, I'd probably run into the same problem. And also, I think tooltip is an AHK facility, no? Thanks -- Vincent
|
|
|
|
|
Logged
|
|
|
|
|
Kruskal
|
 |
« Reply #16 on: May 07, 2010, 12:38:32 AM » |
|
That's a disappointment. So there is no solution consistent with my preferences? I could make it display a small GUI window instead of using a tooltip. This way, you could move it out of the way, leave it open as long as necessary, and close it when you're done. Your thoughts? If I knew how to do it it would be great. Even better than what I am used to -- closing a window is more natural that hotkeying a second time. AND I could even have two GUI windows up at the same time. Thanks -- Vincent
|
|
|
|
« Last Edit: May 07, 2010, 12:42:32 AM by Kruskal »
|
Logged
|
|
|
|
|
Target
|
 |
« Reply #17 on: May 07, 2010, 12:52:03 AM » |
|
What would happen if one instance of the EXE was in its delay when I make the second call to clear the tooltip? If the answer is to my liking, I could make the delay 5 hours, or so, and essentially get the behavior I want. as it stands subsequent calls will kill the existing instance - to change that amend the opening line to #singleinstance, off the only issue here is deciding what tooltip belongs to what call - plus you'll end up with XX instances of the script running concurrently (which may or may not be an issue) My reason not to write a PowerPro script is that I understand THAT even less than my deplorable knowledge of AHK. Also, I'd probably run into the same problem. And also, I think tooltip is an AHK facility, no? I'm with you - I used to run Powerpro strictly as a custom launchbar, and I thought the language looked quite powerful (this seems to be the popular view) but I never was able to get into it. It is probably safe however to assume that powerpro has an equivalent to the tooltip functionality
|
|
|
|
|
Logged
|
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
|
|
|
|
skwire
|
 |
« Reply #18 on: May 07, 2010, 01:02:35 AM » |
|
If I knew how to do it it would be great. Even better than what I am used to -- closing a window is more natural that hotkeying a second time. I'd be more than happy to write this up for you. Give me a few minutes.
|
|
|
|
|
Logged
|
|
|
|
|
Kruskal
|
 |
« Reply #19 on: May 07, 2010, 01:04:24 AM » |
|
What would happen if one instance of the EXE was in its delay when I make the second call to clear the tooltip? If the answer is to my liking, I could make the delay 5 hours, or so, and essentially get the behavior I want. as it stands subsequent calls will kill the existing instance - to change that amend the opening line to #singleinstance, off the only issue here is deciding what tooltip belongs to what call - plus you'll end up with XX instances of the script running concurrently (which may or may not be an issue) [clip] I don't think the multiple instances is an issue, especially if I reduce the ridiculous 5 hour example. But the other question is a worry. Are you saying that there can (or may be) two tooltips at once? If it's not a single instance thing, that would certainly kill my idea. Thanks -- Vincent
|
|
|
|
|
Logged
|
|
|
|
|
Kruskal
|
 |
« Reply #20 on: May 07, 2010, 01:07:45 AM » |
|
What would happen if one instance of the EXE was in its delay when I make the second call to clear the tooltip? If the answer is to my liking, I could make the delay 5 hours, or so, and essentially get the behavior I want. as it stands subsequent calls will kill the existing instance - to change that amend the opening line to #singleinstance, off the only issue here is deciding what tooltip belongs to what call - plus you'll end up with XX instances of the script running concurrently (which may or may not be an issue) [clip] I don't think the multiple instances is an issue, especially if I reduce the ridiculous 5 hour example. But the other question is a worry. Are you saying that there can (or may be) two tooltips at once? If it's not a single instance thing, that would certainly kill my idea. Thanks -- Vincent What a minute-- if the second call kills the first, that is perfect. It will kill the delay (and tooltip window) and, by using the INI thing, otherwise be a nop. Vincent
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Kruskal
|
 |
« Reply #22 on: May 07, 2010, 12:30:23 PM » |
|
That's fantastic. I changed it to permit multiple instances. But that raised the issue of where the info window should go. It would be better to put it at the cursor position in the multiple info window case so that the two window don't go on top of each other. I boldly tried to do that by changing these two lines: Gui, Add, Button, x%x% y%y% w20 h20 Default Hide vmyButton gGuiClose, Exit Gui, Add, Edit , x%x% y%y% w400 h20 ReadOnly , % Path |||||||||||||||| But that just created randomly sized info windows. How should I do it? Many thanks -- Vincent
|
|
|
|
|
Logged
|
|
|
|
|
skwire
|
 |
« Reply #23 on: May 07, 2010, 06:29:27 PM » |
|
How should I do it? You had the right idea...just use the Gui, Show line. Formatted for AutoIt with the GeSHI Syntax Highlighter [ copy or print] ; Use... Gui, Show, % "x " . x . " y " . y, Kruskal ; I prefer this method which uses a forced expression. ; Or... Gui, Show, x%x% y%y%, Kruskal ; When you're first learning AHK, this method probably seems easier.
|
|
|
|
|
Logged
|
|
|
|
|
Kruskal
|
 |
« Reply #24 on: May 07, 2010, 06:38:35 PM » |
|
How should I do it? You had the right idea...just use the Gui, Show line. Formatted for AutoIt with the GeSHI Syntax Highlighter [ copy or print] ; Use... Gui, Show, % "x " . x . " y " . y, Kruskal ; I prefer this method which uses a forced expression. ; Or... Gui, Show, x%x% y%y%, Kruskal ; When you're first learning AHK, this method probably seems easier.
Perfect! You guys are great. Just a small matter of curiosity: Why does the cursor move from the upper-left corner of where the info window now appears to the middle of its header bar? Thanks -- Vincent I have the answer. The missing statement that prevented the behavior I expected was: CoordMode Mouse, Screen
|
|
|
|
« Last Edit: May 08, 2010, 01:30:43 AM by Kruskal »
|
Logged
|
|
|
|
|