PostMessage goes wrong if I press CTRL or SHIFT - autohotkey

HoldLeftClick(600, 400, 4000, WindowName) ; ( coord x, coord y, delay in ms, window name where to hold left click)
HoldLeftClick(x, y, delay, Window) {
PostMessage, 0x201, , ((y<<16)^x), , %Window% ;WM_LBUTTONDOWN
sleep, delay
PostMessage, 0x202, , ((y<<16)^x), , %Window% ;WM_LBUTTONUP
}
I have this code and I am using it to hold left click on a specified window.
My problem is that if I press CTRL key or SHIFT key, bad things happens in that window, same thing happens if the window is in background and I have other window that is active!
Is there a way to prevent this?

Related

Lbutton event seems to disable my dragging

LButton::
MouseClick, Left
if(recodring==true){
mouseGetPos, x, y
xPosPlan[pos] := x
yPosPlan[pos] := y
xPosPlan.push(0)
yPosPlan.push(0)
timePlan.push(0)
pos := pos + 1
return
}
I made a script that records mouse clicks but in this part I dont know why left button dragging got disabled ?
What's happening is that when you press the left button down, the script intercepts that event and presses the left button down and up again. Try replacing
LButton::
MouseClick, Left
by
~LButton::
. This will make the script not intercept that event inthe first place.

Left Mouse Click Not Work if Gui Follow The Mouse Pointer Autohotkey

Left Mouse Click Not Work if Gui Follow The Mouse Pointer Autohotkey.
i Have a Ahk Script that is able that my Gui with Picture Follow the Mouse Pointer.
But The Left Mouse Click does not work. (i can click/run notepad but i can not select Text in notepad!)
i do not now why it does do that? (the Gui+Picture is not on the Mouse Pointer.)
Follow-Pointer.ahk
#SingleInstance force
CoordMode, Mouse, screen
CoordMode, ToolTip, screen
IfNotExist, c5sc29f.gif ;c5sc29f.gif File is roket.gif
URLDownloadToFile, https://i.imgur.com/c5sc29f.gif, c5sc29f.gif
Gui -Caption +LastFound +ToolWindow +AlwaysOnTop
Gui, Margin, 0, 0
Gui, Color, FFFFFF
Gui, Add, Picture, x100 y100 w-1 h50 +BackgroundTrans, c5sc29f.gif ;
;WinSet, Transcolor, FFFFFF
WinSet, ExStyle, +0x20 ; set click through style
gosub, F1
return
F1:: SetTimer Draw, % (switch:= !switch) ? "20" : "-20"
Draw:
MouseGetPos, x, y
y+=10, x+=10
If switch {
Gui Show, x%x% y%y%
;~ ToolTip,% "x" x " y" y,% x+0,% y+50
} else {
Gui Cancel
ToolTip,
}
return
esc::ExitApp
ExitApp
return
Try
Gui Show, x%x% y%y% NoActivate
NoActivate avoids deactivating the currently active window.

Autohotkey: AlwaysOnTop, On, Run ahk_class SunAwtDialog

i want "Run ahk_class SunAwtDialog" window stayAlwaysOnTop. This time its not working. its working with other windows for e.g. google chrom. Here is the code:
CoordMode,Pixel
CoordMode,Screen
CoordMode,Mouse
run_Win = Run ahk_class SunAwtDialog
SetTitleMatchMode,1
IfWinNotExist,%run_Win%
{
MsgBox,:( Oops
Reload
}
SetTitleMatchMode,2
WinSet , AlwaysOnTop , Off , SciTE4AutoHotkey
SetTitleMatchMode,1
WinSet , AlwaysOnTop , On , %run_Win% ; dont work. window stays behind
WinGetPos,x,y,w,h,%run_Win%
MouseGetPos,xM,yM
MouseMove,% x, % y , 10 ; works: mouse is moving to left top of the window
Sleep,500
MouseMove,% xM, % yM , 10 ; works: restore mouse pos
MsgBox, , endOfProgramm1, endOfProgramm2 , 1
Your code snippet
run_Win = Run ahk_class SunAwtDialog
SetTitleMatchMode,1
IfWinNotExist,%run_Win%
Could be translated to
SetTitleMatchMode,1
IfWinNotExist,Run ahk_class SunAwtDialog
. IfWinNotExist, Run ahk_class ... does not make any sense. Remove the run in the contents of yourrun_Win variable.
(See WinTitle for information on how to catch the right window)

change the coordmode from the active window to any window

this is the situation:
1) I have 3 Windows;
2) My mouse is positioned over any of them (active table under the mouse cursor);
3) I have the ahk_id of both Windows (stored in global variables);
4) Every 5 seconds, I would check (regardless of the movement of the mouse cursor), if a pixel of a specific window (window1, window2...) has a certain color;
5) Click with a controlclik of that pixel and regain control of the starting window under the mouse cursor.
checktime(){
var := Mod(A_Sec, 5)
if (var = 0){
checkpixel(window1) ; window1 is an ahk_id, stored in a global variable
checkpixel(window2)
checkpixel(window3)
}
checkpixel(window){
CoordMode, ToolTip, window ; this line of code is definitely wrong, what do you recommend?
pixelgetcolor, color, 440, 295
if(color=0x4E3500){
controlclick, x440 y295, ahk_id %window%
}
thanks in advance for the answers!

Script to open right-click menu and choose menu item

In a specific program, I want to assign a hotkey to the action of right clicking at the cursor's current position, then moving the cursor to choose an item on that menu, then moving the cursor again to choose an item on the sub-menu. I've gotten as far as the first two commands. When I get to the mousemove, no matter what coordinates I put in, the cursor shoots to the upper left corner of the screen, when what I would like it to do is first move 100 pixels to the right and 60 pixels up, then 100 pixels to the right, zero pixels on the y-axis. Clearly I am misunderstanding something. Please advise.
Thanks,
Ellen
s::
MouseGetPos
Click right
sleep, 100
MouseMove, 60, -60, 5, R
Sleep, 100
MouseMove, 200, 0, 5, R
MouseClick, L
return
Ellen, first of all, if at all possible try if you could use keyboard shortcuts.
Please check: Control Panel\Ease of Access Center\Make the keyboard easier to use\Underline keyboard shortcuts and access keys. This will show the shortcuts that you can use. This way you might even find the keyboard shortcut for the menu, instead of using the mouse location.
^+b:: ; Record the location of the menu at the beginnin with [Shift]+[Ctrl]+b
SoundBeep, 500, 500
ToolTip, Click on the "XYZ" Link
KeyWait, LButton, D
MouseGetPos, xPos, yPos
Send, {Esc}
ToolTip
Return
^b::
MouseClick, Right, xPos, yPos
;Mousemove, 100, 60 R
Send, e : OR WHATEVER Shortcut letter OR.....
Send, {Down 3}{Enter} ; IF you want to use down arrow 3 times to get to the item.
Return
Modified, where YOU have to position the mouse on the always changing menu position.
^b::
MouseClick, Right ; presses where the mouse is located
;Mousemove, 100, 60 R
Send, e : OR WHATEVER Shortcut letter OR.....
Send, {Down 3}{Enter} ; IF you want to use down arrow 3 times to get to the item.
Return
If you can identify the menu ID (with AHK Windows Spy, place the mouse over the menu and look at "under the mouse"), you could use controlsend. This would be location independent since controlsend will use the menu ID to send a signal. If you tell me which application you try to control, I could see if controlSend could be used....
Oh b.t.w. I did not know you used XP, the enable shortcut instructions were for Windows 7.
Shouldn't Mousemove be MouseMove instead? It's like that in the docs.
This AutoHotkey script, including a user-created AutoHotkey function should do what you require.
It automates right-clicking a program, and then selecting 3 items on subsequent menus.
The script has been written to work on Media Player Classic,
but certain lines just need to be edited to make it work for your program, TypeTool 3. You specify a comma-separated list with one or more items, i.e. the name of the item to choose in the first menu, and in the second menu item etc.
The vast majority of programs use standard context menus,
so it should work on your program; this is in contrast
to menu bars and other types of controls/resources that vary more between programs.
-
;note: requires Acc.ahk library in AutoHotkey\Lib folder
;https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk
;on right of screen right-click Raw, Save target as...
;the currently assigned hotkey is ctrl+q
;e.g. Media Player Classic, open right-click menu, click items
#IfWinActive, ahk_class MediaPlayerClassicW
^q::
WinGet, hWnd, ID, A
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass not in MediaPlayerClassicW
Return
CoordMode, Mouse, Screen
MouseGetPos, vPosX2, vPosY2
WinGetPos, vPosX, vPosY, vPosW, vPosH, ahk_id %hWnd%
vPosX := Round(vPosX + vPosW/2)
vPosY := Round(vPosY + vPosH/2)
MouseMove, %vPosX%, %vPosY%
vList = View,On Top,Default
MenuRCSelectItem(vList)
MouseMove, %vPosX2%, %vPosY2%
Return
#IfWinActive
;===============
MenuRCSelectItem(vList, vDelim=",", vPosX="", vPosY="", vDelay=0)
{
DetectHiddenWindows, Off
CoordMode, Mouse, Screen
MouseGetPos, vPosX2, vPosY2
(vPosX = "") ? (vPosX := vPosX2)
(vPosY = "") ? (vPosY := vPosY2)
if !(vPosX = vPosX2) OR !(vPosY = vPosY2)
MouseMove, %vPosX%, %vPosY%
Click right
Loop, Parse, vList, %vDelim%
{
vTemp := A_LoopField
WinGet, hWnd, ID, ahk_class #32768
if !hWnd
{
MsgBox error
Return
}
oAcc := Acc_Get("Object", "1", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (Acc_Role(oAcc, A_Index) = "menu item")
if (oAcc.accName(A_Index) = vTemp)
if (1, oRect := Acc_Location(oAcc, A_Index), vIndex := A_Index)
break
vPosX := Round(oRect.x + oRect.w/2)
vPosY := Round(oRect.y + oRect.h/2)
MouseMove, %vPosX%, %vPosY%
Sleep %vDelay% ;optional delay
oAcc.accDoDefaultAction(vIndex)
WinWaitNotActive, ahk_id %hWnd%, , 6
if ErrorLevel
{
MsgBox error
Return
}
}
MouseMove, %vPosX2%, %vPosY2%
Return
}
;==================================================