AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

What's Up with Vista and SendInput, SendPlay, & Hooks?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
instantrunoff



Joined: 13 Jan 2008
Posts: 81

PostPosted: Sat May 17, 2008 9:10 pm    Post subject: What's Up with Vista and SendInput, SendPlay, & Hooks? Reply with quote

There have been scattered reports on the forums here about issues with SendInput and SendPlay using Vista. I've had difficulties also. Some suggestions involve using compatibility mode or running as administrator. Right now, I have UAC disabled, and I can't use SendInput with my Right Alt key-triggered hotkeys, because the Alt gets stuck down even with #HotkeyModifierTimeout 0.
http://www.autohotkey.com/forum/viewtopic.php?t=29607

SendPlay has worked better, if I have the following in the auto-execute section of the script:
Code:
SetBatchLines -1
SendMode Play
Process, priority, , High
and I don't have autohotkey.exe running in compatibility mode.

I've also had problems using a LButton hotkey with a #IfWinExist directive (double-click becomes effectively disabled).

It seems as though however AHK does keyboard/mouse hooks gets weird in Vista. Is there a common source of these issues that could be fixed? Would a keyboard/mouse hook AHK helper running as a service avoid these problems? Thanks.
Back to top
View user's profile Send private message Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Sat May 17, 2008 11:46 pm    Post subject: Reply with quote

The only problem I recall having with SendInput or SendPlay is that SendPlay doesn't work at all. Laughing I have UAC enabled.
Quote:
I've also had problems using a LButton hotkey with a #IfWinExist directive (double-click becomes effectively disabled).
Does this happen all the time, intermittently, or only when the window is active?

Could you post some example scripts, so that I may see these issues for myself?
Back to top
View user's profile Send private message
instantrunoff



Joined: 13 Jan 2008
Posts: 81

PostPosted: Sun May 18, 2008 12:39 am    Post subject: Reply with quote

Since I'm constantly editing my scripts, I don't have handy examples for you. However, using the right alt key to trigger a SendInput resulted in a stuck Alt key:
Code:
>!v::SendInput %longvariable%
Also, using SendInput in general (triggered by a combo hotkey for example) kept the following from working after it was triggered unless I switched windows and regardless of whether I had #UseHook on or off:
Code:
`::PostMessage, 0x112, 0xF060,,,A  ; 0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE (run with highest privileges)
At least, I think it was a stuck Alt key; there was all sorts of weirdness.

SendPlay does work for me with UAC off, and quite nicely.

Here's the actual code for the LButton issue, which I've removed from my main script. The issue happened with neither window actually existed, but the directive was (I believe) for a window group:
Code:

GroupAdd, noclose, EasyCapture
GroupAdd, noclose, Google Calendar - Mozilla Firefox
   #IfWinActive EasyCapture
   `::PostMessage, 0x112, 0xF020,,,A
   #IfWinActive    
   #IfWinActive Google Calendar - Mozilla Firefox ; Hide Window
   `::WinHide A
   #IfWinActive
   
#IfWinExist, ahk_group noclose
   LButton:: ; Hide Google Calendar instead of close when close button is clicked
         CoordMode, Mouse, Screen
         MouseGetPos, x, y, hwnd
         WinGetTitle, title, ahk_id %hWnd%
         IfInString, title, Google Calendar - Mozilla Firefox
            {
            SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
            If ErrorLevel in 9,12,14,20 ; 20 is for Close box but Vista/Aero bug in WM_NCHITTEST
         WinHide ahk_id %hWnd%
         else
         Click down
         }
       IfInString, title, EasyCapture
            {
            SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
            If ErrorLevel in 9,12,14,20 ; 20 is for Close box but Vista/Aero bug in WM_NCHITTEST
         PostMessage, 0x112, 0xF020,,, ahk_id %hWnd%
         else
         Click down
         }
      else
      Click down
        return
   LButton Up::Click Up
 #IfWinExist
 
mButton:: ; Close windows from taskbar except Google Calendar
       if GetMouseTaskButton(hwnd) && hwnd
            {
            WinGetTitle,  wintitle, ahk_id %hwnd%
            IfInString, wintitle, Google Calendar - Mozilla Firefox
            WinHide,  ahk_id %hwnd%
            IfInString, wintitle, EasyCapture
            PostMessage, 0x112, 0xF020,,, ahk_id %hwnd%
            else
           WinClose, ahk_id %hwnd%
           }
       else {
           Click M Down
           KeyWait, MButton
           Click M Up
       }
   return
   
; Volume Control
#MaxThreadsPerHotkey 2
#MaxThreadsBuffer On
^[::
^]::
volctrl:
IfWinNotExist, Volume Mixer
Run sndvol.exe
IfWinNotActive, Volume Mixer
WinActivate, Volume Mixer
Hotkey, ^[, voldown
Hotkey, ^], volup
KeyWait, Control
Sleep 700
WinClose Volume Mixer
Hotkey, ^[, volctrl
Hotkey, ^], volctrl
return
voldown:
Send {Volume_down}
SoundPlay, *-1
return
volup:
Send {Volume_up}
SoundPlay, *-1
return
#MaxThreadsBuffer Off
#MaxThreadsPerHotkey 1

; Functions   

   ; Gets the index+1 of the taskbar button which the mouse is hovering over.
   ; Returns an empty string if the mouse is not over the taskbar's task toolbar.
   ;
   ; Some code and inspiration from Sean's TaskButton.ahk
   GetMouseTaskButton(ByRef hwnd)
   {
       CoordMode, Mouse, Screen
       MouseGetPos, x, y, win, ctl, 2
       ; Check if hovering over taskbar.
       WinGetClass, cl, ahk_id %win%
       if (cl != "Shell_TrayWnd")
           return
       ; Check if hovering over a Toolbar.
       WinGetClass, cl, ahk_id %ctl%
       if (cl != "ToolbarWindow32")
           return
       ; Check if hovering over task-switching buttons (specific toolbar).
       hParent := DllCall("GetParent", "Uint", ctl)
       WinGetClass, cl, ahk_id %hParent%
       if (cl != "MSTaskSwWClass")
           return
   
      
       WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd
   
       hProc := DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
       pRB := DllCall("VirtualAllocEx", "Uint", hProc
           , "Uint", 0, "Uint", 20, "Uint", 0x1000, "Uint", 0x4)
   
       VarSetCapacity(pt, 8, 0)
       NumPut(x, pt, 0, "int")
       NumPut(y, pt, 4, "int")
      
       ; Convert screen coords to toolbar-client-area coords.
       DllCall("ScreenToClient", "uint", ctl, "uint", &pt)
      
       ; Write POINT into explorer.exe.
       DllCall("WriteProcessMemory", "uint", hProc, "uint", pRB+0, "uint", &pt, "uint", 8, "uint", 0)
   
   ;     SendMessage, 0x447,,,, ahk_id %ctl%  ; TB_GETHOTITEM
       SendMessage, 0x445, 0, pRB,, ahk_id %ctl%  ; TB_HITTEST
       btn_index := ErrorLevel
       ; Convert btn_index to a signed int, since result may be -1 if no 'hot' item.
       if btn_index > 0x7FFFFFFF
           btn_index := -(~btn_index) - 1
      
      
       if (btn_index > -1)
       {
           ; Get button info.
           SendMessage, 0x417, btn_index, pRB,, ahk_id %ctl%   ; TB_GETBUTTON
      
           VarSetCapacity(btn, 20)
           DllCall("ReadProcessMemory", "Uint", hProc
               , "Uint", pRB, "Uint", &btn, "Uint", 20, "Uint", 0)
      
           state := NumGet(btn, 8, "UChar")  ; fsState
           pdata := NumGet(btn, 12, "UInt")  ; dwData
          
           ret := DllCall("ReadProcessMemory", "Uint", hProc
               , "Uint", pdata, "UintP", hwnd, "Uint", 4, "Uint", 0)
       } else
           hwnd = 0
   
          
       DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pRB, "Uint", 0, "Uint", 0x8000)
       DllCall("CloseHandle", "Uint", hProc)
   
   
       ; Negative values indicate seperator items. (abs(btn_index) is the index)
       return btn_index > -1 ? btn_index+1 : 0
   }
Back to top
View user's profile Send private message Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Sun May 18, 2008 6:11 am    Post subject: Reply with quote

Quote:
>!v::SendInput %longvariable%
This doesn't give me any problems. What would be typical contents for longvariable?
Quote:
Here's the actual code for the LButton issue, which I've removed from my main script. The issue happened with neither window actually existed, but the directive was (I believe) for a window group:
So when you run that code, double-click doesn't work?

I've tried the code you posted with and without my two main scripts, which use mouse and keyboard hooks. I wasn't entirely sure what to look for, though. Is it an intermittent issue?

Some information that might be useful:
  • Do you have the latest version of AutoHotkey (v1.0.47.06)? I do.
  • Are you using 32-bit or 64-bit Vista? I'm on 32-bit Vista.
  • Do you use Logitech SetPoint, Microsoft IntelliMouse or similar? I don't.
  • Can you reproduce these issues with no other scripts or similar applications running?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group