Why I can't get msgbox to show up in a while loop? - autohotkey

MButton::
Send {LWIN down}{TAB down}{LWIN up}{TAB up}
while GetKeyState("MButton")
{
Msgbox 1
}
return
I am new to Ahk, hope someone could enlighten me of my error.

Use "p" parameter to get the actual physical state of the button:
GetKeyState("MButton","p")

Related

How to activate button in a loop

I want to activate the button called EditBUtton2, but I'm finding it difficult. I've only been able to successfully identify it in a loop, just not activate it.
^+f7::
WinGet, OutputVar, ID
MsgBox, "%OutputVar%"
WinGet, ActiveControlList, ControlList, A
Loop, Parse, ActiveControlList, `n
{
if(A_LoopField = "EditButton2")
MsgBox, "found button successfully."
; I want to activate this button, but this doesn't work:
Send, {Space}
;controlsend,, {Space}, %A_Loopfield%
}
return

how can i create an equivalent "$" effect on mouseclick events in AHK?

I'm trying to create an AHK script where the right mouse click is intercepted, similar to a $ call would work with a keyboard press. This is the code I've tried but the right click still is sent to the program.
$capslock::
send {u down}
var = 0
return
$capslock up::
send {u up}
var = 1
return
$rbutton::
if(var) {
;
} else
sendinput, {s}
return
Any help would be appreciated!

combining hotkeys

I'm trying to make an autoclicker in autohotkey but can't get it to work.
I have some knowledge about autohotkey but it is not very much:
<^LButton::
Loop
{
SetMouseDelay 0.001
Click
If(GetKeyState("LButton","P")=0)
Break
}
It works with <^LButton as hotkey, but not <^nLButton.
Therefore I need help with hotkey-combinations.
I get the errorcode:
Line Text: <^nLButtonSuspend
Error: This line does not contain a recognized action.
If you want to combinate Three keys as a Hotkey.
Click the Keys : [Ctrl] + [n] + [Lbutton] = Do a Action.
You can Try this:
example1.ahk
;#notrayicon
#SingleInstance force
^n::
GetKeyState, state, Lbutton
if state = D
{
Loop
{
send a
;SetMouseDelay 0.001
;Click
If(GetKeyState("LButton","P")=0)
Break
}
} else {
send b ;this codeline is only so that you can test it out in notepad. - you can remove this
}
Return
esc::exitapp
note : It is not perfect but the answer is close to your Question.

Autohotkey: Ctrl + 1 mapping

I want to remap mouse click to a button depend on a state of Numlock. If Numlock is 'ON' then I want the normal behavior else map to mouse click. The script I created below works fine but I have trouble remapping CTRL+1.
SHIFT+1 will result in '!' so it is simple to do but I don't know what's the behavior for CTRL+1 is. The current script has the dummy "Send, {^1}" but that is not the real behavior.
I appreciate any suggestion.
*The Keywait is for simulating holding the mouse button and the script is enable/disabled base on Numlock state.
$1::
if GetKeyState("NumLock","T")
Send, {1}
else
{
Click down,
KeyWait 1
Click up
}
Return
$+1::
if GetKeyState("NumLock","T")
Send, {!}
else
{
Click down,
KeyWait 1
Click up
}
Return
$^1::
if GetKeyState("NumLock","T")
Send, {^1}
else
{
Click down,
KeyWait 1
Click up
}
Return
The following should do what you've described, with some cleanup to the code itself. I also recommend reading up on the various Send modes, as SendInput is superior in just about every way possible.
$1::
if GetKeyState("NumLock","T")
SendInput, 1
else
{
Click down
KeyWait 1
Click up
}
Return
$+1::
if GetKeyState("NumLock","T")
SendInput, {!}
else
{
Click down
KeyWait 1
Click up
}
Return
$^1::
if GetKeyState("NumLock","T")
SendInput, ^1
else
{
Click down
KeyWait 1
Click up
}
Return

How do I send a singular key press automatically?

Update 05.08.16 - 12:08 AM:
Here is a video of me trying to get this to work: https://youtu.be/h9gAirlUGyI
So, I'm trying to have a key pressed once on program launch.
This is what I have:
{
Send, {F11}
}
Now when I launch the program it doesn't send the key.
Help?
flag = 0
processName := "xenia.exe"
Loop
{
If ProcessExist(processName)
{
WinGetTitle, title, ahk_exe %processName%
IfWinActive, %title%
{
if flag = 0
{
Send, {F11}
flag = 1
}
}
else
{
flag = 0
}
}
Sleep, 1000
}
ProcessExist(Name)
{
Process,Exist,%Name%
return Errorlevel
}
Per your other question and my comment there:
; This code both launches and fullscreens XENIA . . .
#Persistent
#SingleInstance, Force
Run, xenia.exe
Sleep, 500
GoSub, DoIt
return
numpad0::
GoSub, DoIt
return
DoIt:
IfWinExist, ahk_class XeniaWindowClass ahk_exe xenia.exe
{
WinActivate, ahk_class XeniaWindowClass
#IfWinActive, ahk_class XeniaWindowClass
{
Send, {F11}
}
}
return
Now, if the question is REALLY about launching xenia with a file you've clicked on, e.g., using an explorer extension, there are ways of making it work (by adding the script to the registry and/or passing the file name and path into the command line. Again, please give us details as to what you want to happen!