Using xdotool to ctrl-click-drag in scrcpy window - xdotool

This is for Debian 11:
I am trying to script a ctrl+click+drag motion within a scrcpy window. This is what I have so far:
#!/bin/bash
xdotool search --desktop 0 --class "scrcpy" windowactivate
unset x y w h
eval $(xwininfo -id $(xdotool getactivewindow) |
sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
-e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
-e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
-e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
let "zosx = ( x + ( w / 4 ))"
let "zosy = ( y + ( h / 4 * 3 ))"
let "zoex = ( x + ( w / 2 ))"
let "zoey = ( y + ( h / 2 ))"
xdotool mousemove --sync $zosx $zosy
xdotool keydown Control_L
xdotool mousedown 1
xdotool mousemove --sync $zoex $zoey
xdotool mouseup 1
xdotool keyup Control_L
Alas, it does not work. The mouse should start 75% from top and 25% from left in the window, then hold down ctrl, hold down the mouse 1 button, drag to 50% / 50% of window and release both the mouse button and the control key.
As you may guess, this is to achieve a "zoom out" type of function inside of the scrcpy window.
The coordinate DO calculate correctly, so it seems to be an issue with the keydown / mousedown / mousemove
Advice?

Related

Avoid overlapping modifiers for hotkey

Use case: my laptop keyboard (a Qwerty one with Azerty stickers on it) is missing the « < and > » key, which I absolutely need. Therefore I'm writing an AutoHotKey script to be able to type these characters.
Expected behavior: inputting « Left Ctrl + W » should programmatically type "<", and inputting « Left Ctrl + Left Shift + W » should programmatically type "<".
Issue: with the following script, inputting « Left Ctrl + W » programmatically type "<>", so the hotkeys seem to be overlapping… but I thought AutoHotKey was expected to not trigger a hotkey when extra modifiers are inputted.
; Left Ctrl + W
<^w::
SendInput <
; Left Ctrl + Left Shift + W
<^<+w::
SendInput >
However, the following script works as expected. I just added a "Return":
; Left Ctrl + W
<^w::
SendInput <
Return
; Left Ctrl + Left Shift + W
<^<+w::
SendInput >
Question: is it normal that AutoHotKey inputs "<>" with my first script? Is adding such "Return" the required syntax indeed, even though the script consists of just these 2 hotkeys?
Yes, this is normal.
Either write the hotkeys on a single line, otherwise use return.
Valid syntaxes:
; Left Ctrl + W
<^w::SendInput <
; Left Ctrl + Left Shift + W
<^<+w::SendInput >
or
; Left Ctrl + W
<^w::
SendInput <
return
; Left Ctrl + Left Shift + W
<^<+w::
SendInput >
return

PostMessage goes wrong if I press CTRL or SHIFT

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?

How can I keep modifier of hotkey active in AutoHotkey?

A media keyboard I'm using doesn't have a full set of keys, so I'm trying to map alternatives using AutoHotkey. Basically, I want to use the Alt Gr key together with some other keys to simulate the missing keys. This is what I've done:
<^>!,::send {Home}
<^>!.::send {End}
<^>![::send {PrintScreen}
<^>!]::send {Insert}
However, if I want to do the equivalent of Shift + Home (to select all text to the beginning of a line), this doesn't work as I'd hoped. I know I can put a * at the beginning of the line so that Home is still sent even when I'm holding Shift, but the problem is that I'd like the Shift key to still be active so that I get the equivalent of Shift + Home.
Likewise, if I want to do Alt + Print Screen then holding Alt while pressing Alt Gr + [ doesn't have the desired effect.
I assume I could set up extra rules to catch those combinations, but surely there must be a way to just have AutoHotkey not discard whatever modifier I'm holding at the time I hit the hotkey so that whatever combination I use it'll work?
EDIT (2014-07-16):
Here is the latest version of my script, which includes comments that make it clear what I'm wanting to achieve. Everything in this script works except for the last line. For some reason, even though I'm trying to send Alt + PrtScn it gets treated as just PrtScn.
; Home ( by pressing AltGr + , )
<^>!,::send {Home}
; Shift + Home ( by pressing Shift + AltGr + , )
+<^>!,::send +{Home}
; End ( by pressing AltGr + . )
<^>!.::send {End}
; Shift + End ( by pressing Shift + AltGr + . )
+<^>!.::send +{End}
; Insert ( by pressing AltGr + [ )
<^>![::send {Insert}
; Shift + Insert ( by pressing Shift + AltGr + [ )
+<^>![::send +{Insert}
; PrtScn ( by pressing AltGr + ] )
<^>!]::send {PrintScreen}
; Alt + PrtScn ( by pressing LeftAlt + AltGr + ] )
<!<^>!]::send !{PrintScreen}
Using the {Blind} attribute will pass on the modifier keys.
e.g.
<^>!,::send {Blind}{Home}
See: Send existing modifiers with a key in autohotkey?
It turns out that some of the combinations I wanted to do with Autohotkey, involving the AltGr key, are not possible due to AltGr itself actually being a combination of Control and Right Alt. Therefore, not all modifiers are available for use together with that key, and some of the AutoHotkey commands give unwanted/unexpected results when trying to use them together with AltGr.
The final version of the script I'm using with my new keyboard (the UK version of the Microsoft All-in-One Media Keyboard) is as follows:
; Set an initial state for the lock keys
SetCapsLockState, off
SetNumLockState, on
SetScrollLockState, off
; Home ( by pressing AltGr + , )
<^>!,::send {Home}
; Shift + Home ( by pressing Shift + AltGr + , )
+<^>!,::send +{Home}
; End ( by pressing AltGr + . )
<^>!.::send {End}
; Shift + End ( by pressing Shift + AltGr + . )
+<^>!.::send +{End}
; Insert ( by pressing AltGr + [ )
<^>![::send {Insert}
; Shift + Insert ( by pressing Shift + AltGr + [ )
+<^>![::send +{Insert}
; PrtScn ( by pressing AltGr + ] )
<^>!]::send {PrintScreen}
; Alt + PrtScn ( by pressing Alt + ] )
!]::send !{PrintScreen}
; Scroll Lock ( by pressing AltGr + \ )
<^>!\::send {ScrollLock}
; Pause/Break ( by pressing AltGr + p )
<^>!p::send {Pause}
; Win + Pause/Break ( by pressing Shift + Alt + p )
+!p::send #{Pause}
; Control + Pause/Break ( by pressing Shift + Ctrl + p )
+^p::send ^{CtrlBreak}
; Run Calculator ( by pressing AltGr + c )
<^>!c::Run Calc

BetterDesktopTool and Autohotkey

I have setup a keyboard shortcut in BetterDesktopTool that has a sort of mission control view for Windows.
The shortcut is Alt + Tab and I want to map my F3 key to that. But it won't work in Autohotkey
#InstallKeybdHook
#SingleInstance force
SetTitleMatchMode 2
#Include Apple Wired Keyboard.ahk
SendMode Input
; --------------------------------------------------------------
; NOTES
; --------------------------------------------------------------
; ! = ALT
; ^ = CTRL
; + = SHIFT
; # = WIN
; media/function keys all mapped to the right option key
F7::SendInput {Media_Prev}
F8::SendInput {Media_Play_Pause}
F9::SendInput {Media_Next}F3F3
; F10::SendInput {Volume_Mute}
; F11::SendInput {Volume_Down}
; F12::SendInput {Volume_Up}
; swap left command/windows key with left alt
LWin::LAlt
LAlt::LWin
; Misc.
F20::WinMinimize A
*F3::SendInput {Alt}{Tab}
; F13-15, Volume
F13::SendInput {Volume_Mute}
F14::SendInput {Volume_Down}F3F3
F15::SendInput {Volume_Up}
;F16-19 Standerd
F16::SendInput {PrintScreen}
F17::SendInput {ScrollLock}
F18::SendInput {Pause}
F19::Run wmplayer
I know that my Alt + Tab shortcut works, but it doesn't activate the hotkey for BetterDesktop
Have a look at this documentation:
http://www.autohotkey.com/docs/Hotkeys.htm
Search for "Substitutes for Alt-Tab"

How do you send an alt0189 to autohotkey

In word and other programs when you hold down the alt key and type 0189 on the number keyboard you will get the half inch symbol ½. How can I send this sequence in autohotkey using a hot key
Thanks in advance
Tim
In general: Send, {ASC 00189}
I do it this way:
; ================================== FRACTIONS ==================================
^2::
Send, ½
TrayTip, For 2 Squared,press Ctrl + Shift 2,1,1
Return
^3::
Send, ¾
TrayTip, For 3 Cubed,press Ctrl + Shift 3,1,1
Return
^4::Send, ¼
; ================================== POWERS ==================================
+^0::Send, °
+^1::Send, ¹
+^2::Send, ² ; Shift Control 2#
+^3::Send, ³ ; Shift Control 3#
Ctrl+2 = ½
Ctrl+3 = ¾
Ctrl+4 = ¼
ShiftCtrl + 0 = °
ShiftCtrl + 1 = ¹
ShiftCtrl + 2 = ²
ShiftCtrl + 3 = ³