Autohotkey - Enable all mouse click functionality and also play a sound - autohotkey

I have this autohotkey script, I want to play a sound on mouse click. But this script doesn't let me drag windows or resize window or highlighting text using mouse left click.
Any idea how I can have all mouse left click functionality and also play the Error.wav sound on every click?
LButton::
MouseClick, Left
SoundPlay, C:\Windows\media\Error.wav
return

Your current script is not only listening for a mouse click, but also emulating a second click with MouseClick, Left. It seems that's not what you want. Also use ~ to ensure that
When the hotkey fires, its key's native function will not be blocked
(hidden from the system)
~LButton::SoundPlay, C:\Windows\media\Error.wav
See Hotkeys documentation.

Related

Detect when Ctrl is pressed

I'm implementing a ctrl+click solution for links in a textview and am having trouble setting the cursor to a hand when Ctrl is being held. Right now I
set the cursor to a hand in mouse motion when mouse moves inside the textview and control is pressed and the mouse is on top of a link (I use TextTag to style the links, so I just check whether the text below the mouse has this tag.).
set the mouse cursor back to the text edit cursor otherwise
However, when the mouse is on top of the link and I press Ctrl (without moving the mouse) the cursor does not change. Clearly, no mouse motion was detected so this is the expected behavior. My problem is how to implement this. I tried adding a keypress handler to the textview, but
it only fires when the textview has focus. This is not always the case, since I might not click the textview before clicking the link.
event.get_state() only comes with CONTROL_MASK if other key is pressed as well.
I receive no information about the mouse cursor, so I end up not knowing where it is pointing inside the keypress handler.
How can I solve these issues so I can have a Ctrl+click solution that shows adequate cursor when Ctrl is being pressed? I can already solve it by considering only mouse motion. The problem is how to detect Ctrl being pressed and react accordingly without mouse motion.

Access the MDI toolbar menu with AutoHotKey ControlSend

Automating a process that is being run on a RDP session, I have to use ControlSend, and not Send command in AutoHotKey.
The WindowSpy doesn't find any control on the MDI toolbar, and there are no shortkey to the menu item I want to access (Filter..). How may I open the toolbar and select the item?
I've tried
ControlSend, ahk_parent, {alt}, ahk_class FNWND3170 ;Open project folder in treeview
But with no success.
I've considered using AutoIT, but I don't think that would help as the AutoIt spy doesn't pick up the control either.
Sorry, but think of the RDP window (or even full screen) as an ever-evolving bitmap image. Your PC and autohotkey have no idea what is behind the picture. Can you run the ahk script in the remote pc itself? Keep in mind, the RDP client handles your mouseclicks and keyboard (and even voice) entirely by re-directing inputs, etc. So best bet is to do a mouse click in the appropriate spot by running a script from outside the window:
CoordMode, TargetType [, RelativeTo]
Click, 44, 55 ; Clicks the left mouse button once at coordinates 44, 55 (based on CoordMode).
Use the CoordMode "RelativeTo" flag to set to "Relative" so coordinates are relative to the active window. You may have to click twice, once to activate the RDP window and then to click at the mouse position.
See https://www.autohotkey.com/docs/commands/Click.htm and https://www.autohotkey.com/docs/commands/CoordMode.htm for info.
Hth,

Replace a key for an external mouse

I have an external mouse which also register a HID keyboard in Device Manager. One of its button shows start menu. I want to replace it with mouse click. Since I also have an inbuilt keyboard I don't want to replace its start button. I want to replace start button from the external mouse
Try using the #InstallKeybdHook and look in the KeyHistory when you have pressed the button!
This can atleast tell you if your mouse button has the same virtual key code or scan code as the built-in keyboards key
This is a step by step guide http://ahkscript.org/docs/KeyList.htm#SpecialKeys

Keyboard's event considered like mouse's click on the GUI

I'm using GUI, I have 4 button in my GUI and my callback detect mouse and keyboard event.
Mouse event concerns click on button
Keyboard event concerns space press to play a .wav
When the position of mys cursor's mouse is on one of the 4 buttons, and I press space I've the following error
"Undefined function 'pushbutton4_KeyPressFcn' for input arguments of type 'struct'."
I didn't define any keyboard shortcut for the GUI's button, how can I avoid this error ?
Thanks !
Open the GUI in GUIDE.
Right click on the button and chose 'Property Inspector'.
Scroll down to the 'KeyPressFcn' field and delete the value.
Save the GUI and try again.

Autohotkey - capture extra mouse buttons

Can autohotkey capture nonstandard mouse buttons? I use a five-button mouse (Microsoft Wireless Laser Mouse 6000).
XButton1 and XButton2 according to the documentation on autohotkey.com.
The following URLs show how to have autohotkey log all keyboard and mouse events, and how to look at the log autohotkey generates of those events.
http://www.autohotkey.com/docs/commands/_InstallMouseHook.htm
http://www.autohotkey.com/docs/KeyList.htm#SpecialKeys (special keys section)
Based on this, you can find out about all mouse and keyboard events by creating an autohotkey script as such:
#InstallKeybdHook
#InstallMouseHook
Once you run the script, you can double click on the tray icon for that script, then go to View > Key History and Script Info (Ctrl K)
Based on this information, I figured out that my mouse driver is already redefining the extra mouse buttons to other keys. However, I can re-map those keys by going to Control Panel > Mouse, selecting the desired button, and using the "Macro..." option in the mouse configuration (this is a special configuration only for the Microsoft Wireless Laser Mouse 6000 v2). In the macro dialog, I can define keystrokes for those mouse buttons to send (only one per mouse button). Next, I can use AutoHotkey to watch for whatever keystrokes I have defined, and perform specific actions based on those keystrokes.
You need to capture the scancode of the key and then use that. You can find a script in 5th post of this thread, written by Skan, which will allow you to do this. Just run that and click on the GUI with the mouse button you wish to determine the scancode. Then use the scancode in place of the normal key when you create the hotkey.
There is also a built in method of retrieving keys which is documented at the bottom of this page under the heading "Special Keys". Essentially, AHK logs your key presses and automatically records the scancodes for you.
To use the scancode as a hotkey, you just do the following:
SC###:: ;Your code here
Where ### is replaced with the code of your key (or mouse button).