Detecting ahk class of YouTube HTML5 player - autohotkey

I'd like to assign back and forward YouTube keyboard commands to my middle and right click mouse buttons respectively. Unfortunately, with HTML player it is not possible to differentiate the youtube video window from Firefox ahk class as I did before with flash player. I've tried MouseClick commands and simple reassigning keyboard commands to mouse but none of it worked. For some reason autohotkey couldn't be made to send no click commands to the HTML video window and I couldn't even reassign the basic functions of the mouse middle click for example, to make it work as a Left keyboard command.
Anyone has an idea how to make a working autohotkey script that would enable me to turn Left and Right keyboard commands into mouse Right and Middle button clicks?

Like this?
#If YouTubeHtml5Active()
RButton::Right
MButton::Left
#If
YouTubeHtml5Active() {
tmmBackup := A_TitleMatchMode
SetTitleMatchMode, RegEx
youtubeVideoAvtive := WinActive(".+ \- YouTube \- Mozilla Firefox")
SetTitleMatchMode, %tmmBackup%
If youtubeVideoAvtive
Return True
}

Assuming you run on Win10:
I've tried MouseClick commands and simple reassigning keyboard commands to mouse but none of it worked.
AutoHotkey in Windows 10 - Hotkeys not working in some applications Some programs need AutoHotkey to be ran in admin mode, otherwise hotkeys are not recognized.

I've found a simple script doing this on autohotkey forum http://www.autohotkey.com/board/topic/69720-controll-youtube-volume-with-mousewheel/, here it is, works like a charm:
SetTitleMatchMode 2
#IfWinActive YouTube
RButton::Send {Left}
MButton::Send {Right}
return

Related

Prevent WheelUp on !WheelUp

I am trying to send the letter "a" when ALT is pressed and the mouse wheel is scrolled up.
This code works partially:
!WheelUp::
Send, a
return
In Vscode or just the plain Windows Texteditor however, I notice some scrolling if I scroll to hard with my mouse while pressing ALT.
Can this be fixed?
First thing is to check for running applications with high priority. These may interfere with AHK. For example I had similar issues while running AIMP (music player) in the background.
Setting the script's priority might be worth trying too.

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

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.

Sending keystrokes and mouse clicks using Scala

I've previously used AutoHotkey to send keystrokes and mouse clicks to automate interaction with GUIs and browsers. How do I send keystrokes and mouse clicks this time using Scala?
You can use java.awt.Robot.
val robot = new java.awt.Robot
robot.mouseMove(100,100) // Cursor will jump to the top left of your screen
Note that you have to enter text keycode by keycode (see java.awt.event.KeyEvent). This is pretty annoying, but you can write code to automate the pressing and releasing of keys. (You do need to release every key you press! It's emulating the keyboard....)
JNA + Windows API
I had to send input to a background window and it worked really well for me.

autohotkey activate window twice deactivate it?

i have this code AutoHotkey Code:
#NoTrayIcon
If WinExist("Mozilla Thunderbird")
{
WinActivate, Mozilla Thunderbird
}
Else
{
Run "c:/Users/xah/Desktop/Mozilla Thunderbird.lnk"
WinActivate
}
Return
ExitApp
activated by a key.
but when run twice (sometimes pressed the key twice), it seems to deactivate the window and change mouse position.
how to fix that?
(this is a pain for me because i have auto window focus on. When mouse position changes to another location, that window pops up to front)
thanks.
someone at ahk forum answered it.
http://www.autohotkey.com/forum/post-413075.html#413075
basically, my script is actually running the Else clause everytime.
What i need is to add
SetTitleMatchMode, 2
in the beginning, so the title matches if it contains the string.

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).