I try to automate a process where I have to perform two mouseclicks. One should go to an absolute position and perform a left click:
Click, 492, 256, Right
And the second should select a value from the dropdown box. The exact (absolute) location of the value in the dropdown list which should be selected is:
Click, 801, 571, Left
I hacked together this code:
#r::
Click, 492, 256, Right
Sleep 1000
Click, 801, 571, Left
But this does not seem to work. It performs a left click at in the situation I want but the dropdown box is not selected. Any thoughts on what I am doing wrong at the second Click?
It could be that the dropdown box doesn't allow "instantaneous" clicks, I had this problem also some time ago. My first post here, so sorry if format is bad...Try the following:
#r::
Click, 492, 256, Right
Sleep 1000
MouseMove, 801, 571
Sleep 100 ; if code works, try to deactivate this one
Click, Down Left
Sleep 100
Click, Up Left
If this doesn't work:
Try to lower Speed on MouseMove somewhat, via additional option.
Try changing SendMode to Input for this part of your script
Related
running AHK in Windows 10, and I'm trying to create shortcuts for the Alt+Space menu. Specifically, I often use this sequence:
Press keys Alt+Space (bring up the window menu)
Press key S (select Size to resize)
Press key Left (now moving the mouse is resizing your window horizontally)
Press key Up (now moving the mouse is resizing your window in all directions)
Once this sequence is pressed, you can move your mouse to resize the active window as if you click-dragged the top-right corner, without having to hunt for that corner. (to finalize the resizing you can press Enter of LeftMouseKey, or Esc to abort). I'd like to get to this state with a single shortcut.
Here is my current script, binding to Winkey+Ctrl+Shift+1
;resize window from Top-Left
#^+1::
SendInput !{Space}
Sleep 100
SendInput s
Sleep 100
SendInput {Left}+{Up}
Return
It works mostly, but sometimes the active window will consume the s {Left} {Up} commands, rather than the popup menu. Thus, sometimes this shortcut will result in the active window like VSCode having the "s" character and the cursor 1 line up from before (as if typing s {Left} {Up}), and a visible Alt+Space menu.
I initially used Sleep 10 and thought Sleep 100 would fix this, but it didn't. The shortcut already feels slow with 2x Sleep 100 built in.
I'd like to test if the Alt+Space menu is open before SendInput s and preferably make sure I'm sending to the menu rather than the main application.
I was unable to reproduce the problem using your method. Perhaps try using Send, SendEvent, SendPlay, SendRaw, #InstallKeybdHook, #UseHook
Alternatively, use Autohotkey's WinMove statement:
This resizes the active window such that the upper left hand corner is at the current mouse position
#^+1::
CoordMode Mouse, screen
id := WinExist("A")
WinGetPos x, y, width, height, ahk_id %id%
MouseGetPos mx, my
neww := width + x - mx
newh := height + y - my
WinMove % "ahk_id" id,, mx, my, neww, newh
return
The menu itself is ahk_class #32768, so waiting for it to exist seems to work for me.
#^+1::
Send , !{space}
WinWait , ahk_class #32768 ,, 1 ; Waits 1s for menu to exist
If !ErrorLevel ; ErrorLevel is 0 if menu exists
Send , s{left}+{up}
Return
Jim U's alternative solution is a more reliable way of doing what you're trying to achieve, but this will make what you currently have work.
Autohotkey Example Needed
Need some help, please. I've searched and can't seem to find an example of what I need.
What I want to do is create a ahk dialog box with a button (I can do this part), and when I click on it, it will type some text into another window. Basically, I want want to offload the "shortcut" to a "mouse click". But, without mapping a shortcut.
Something like this:
When user clicks BOX1, "text" is stored. Then, when user clicks elsewhere, vBOX1 is typed into the cursor location of the window activated by that click
I hope I'm explaining this succinctly. Any help would be appreciated.
Here are two possible alternatives:
First alternative expands #scso's suggestion:
~LButton::
sleep, 200 ;give the window below the cursor some time to get activated
Send, %vBOX1%
return
Now this may seem fine but what it actually does is type the text EVERY time you click the mouse in ANY window. Let's put an additional check so if vBOX1 is empty it doesn't type anything.
~LButton::
sleep, 200 ;give the window below the cursor some time to get activated
If (vBOX1 != "")
{
Send, %vBOX1%
vBOX1 := "" ; clears the contents of vBOX1
}
return
Second alternative:
You use the mouse clicks normally and the text gets typed only when you do Control + Click.
So in order to type the text you need to click once to select the window and then control+click to do the actual typing
~^LButton::
Send, %vBOX1%
vBOX1 := "" ; clears the contents of vBOX1
return
You can expand both alternatives by adding commands for detecting the active window and then typing the text or changing the mouse click combination to something else.
I am trying to write a script to select something from a drop down on a webpage and then tab to the next option and input text, then enter. FYI, this is my first script.
I have to create groupings and select from different areas. I have seen places where people have scripts to select certain things but says that can only work in IE browser. I will be using either firefox or chrome but not IE.
^q::Click, 284, 427 ;
Send {Up 10}
Send {Tab} ;
sleep 50 ;
Send BWI{Enter}
return
So what I want it to do is when I press control q, it will go to position 284,427 and click. The dropdown defaults to the bottom option. So I put in code to go up 10 which would select the 10th option from the bottom. Then I want it to tab. That will select the 10th option and go to the next text box at which point it will enter the text BWI and then enter. The BWI is a filter that will show all of the items that have BWI in their name.
Currently, it goes to the dropdown and clicks. Then it does nothing else.
To have more than one command executed by a hotkey, put the first line beneath the hotkey definition and make the last line a return:
^q::
Click, 284, 427
Send {Up 10}
Send {Tab}
sleep 50
Send BWI{Enter}
; ...
return
https://autohotkey.com/docs/Hotkeys.htm#Intro
Hi all i have this piece of code that cant get it to work, please need an hand.
portal(){
portalCommand:
BlockInput On
SendInput {i}
Sleep 2
MouseClick, right, 1775, 795
SendInput {i}
Sleep 2
MouseClick, left, 955, 380
BlockInput Off
return
}
The problem here i dont know why is not sending or it does to fast input I then Right Click input i again and left click, any sugestions please?
Per my comment:
portal(){
portalCommand:
BlockInput On
SendInput i
Sleep 2000
MouseClick, right, 1775, 795
SendInput i
Sleep 2000
MouseClick, left, 955, 380
BlockInput Off
return
}
i forgot to mention that im bad at programming is just a hobby and need it for a game to open inventory when task"{i}" is pressed about sleep you are right i have made my home work in the mean time and read about autohotkeys and stuff and i got the perfect working result thanks anyway :) here is my working code that is what i wanted and i will wxplain aftewards (sry for my english guys i think is not so good i have not study english just learned on the way:)
portal(){
portalCommand:
BlockInput On
;Pressing Space if any inventory is open
Send {space}
Sleep 50
;Opening Inventory
SendInput {i}
Sleep 200
;Move the mouse to a specific location
MouseMove, 1770, 790
Sleep 400
;Pressing Mouse Right Button
Send, {RButton}
Sleep 400
;Move the mouse to a specific location
MouseMove, 600, 370
Sleep 400
;Pressing Mouse Left Button
Send, {LButton}
BlockInput off
return
}
The give up code is a solution for me that actually works without any issue and it does send spacebar (that is the game setup to close any inventory opened) then sends "i" key to open the inventory of the character and goes to defined location making righ click on town portal scroll and after that goes back to defined location and left click on it to enter to the portal (that means going to town) the position is based on the monitor max resolution so the coordinates can be adjusted for anyone needs in case someone else need or whant to use this code ;)
I found an autohotkey script that I need to tweak so that pressing the button results in the left mouse button being held down for approximately 1800 miliseconds. This is what I've got so far but I'm doing something incorrectly.
F1::
alt := not alt
if(alt)
{
Click down ; Sleep, 1800
}
Click up
return
Any help you can offer would be greatly appreciated.
Semicolon punctuation mark, ;, is used for comments.
The Sleep command is commented out, so remove the semicolon:
Click, down
Sleep, 1800