Select whole words when mouse hovers over- Autohotkey - windows

If the cursor is of the IBeam type and the F20 key is pressed and dragged, the text is selected with the shortcut Ctrl + Shift + right (or in the direction to which it is moved) .
Is there any way of doing this? https://imgur.com/a/Rqrfwjk
I have this code but it is based on the number of pixels moved and not on whether the cursor is over a word
#If WinActive("ahk_exe chrome.exe") && A_Cursor = "IBeam"
~LButton::
Click
MouseGetPos, x1
SetTimer, Check, 100
SoundBeep, 1500
KeyWait, LButton
SetTimer, Check, Off
SoundBeep, 1000
Return
#If
Check:
MouseGetPos, x2
f := Floor(Abs((x2 - x1) / 110))
Switch
{
Case x2 > x1: Send ^+{Right %f%}
Case x2 < x1: Send % "{Right}^+{Left " f + 1 "}"
}
Return

Related

Optimising PixelSearch

I need to optimise this AHK script, currently the script runs in around 2 seconds. I would ultimately like it to run >1 second, the best case would be 0.6 seconds. The basic functionality is the script is clicking on red boxes, of which there can be between 2 - 8. I'd love some help on ways to increase the speed of this script if possible.
Thanks, code below.
1::
; Activate the target window
WinActivate, Paint
; Define the search area
SearchLeft := 1047
SearchTop := 572
SearchRight := 1222
SearchBottom := 650
SetDefaultMouseSpeed, 0
; Start the timer
StartTime := A_TickCount
; Loop through all pixels in the search area and click on them
Loop {
; Search for the next pixel
PixelSearch, Px, Py, SearchLeft, SearchTop, SearchRight, SearchBottom, 0x0000FF, RGBFast, Fastest
if (ErrorLevel = 0) {
; Click on the pixel
Click, %Px%, %Py%, 1
}
else {
; If no pixel is found, exit the loop
break
}
}
; Calculate the elapsed time
ElapsedTime := A_TickCount - StartTime
; Output the elapsed time as a message box
MsgBox, % "Script completed in " . ElapsedTime . " milliseconds."
3::ExitApp

Quick selection script issue

I have this autohotkey script that points to the entire word by pointing to the first word and if the cursor scrolls 110px in one direction. The code uses Ctrl + Shift + {Right} to select the next words, but for the previous words you can't use Ctrl + Shift + {Left} because the current word is deselected.
How could I solve this problem so that it selects well in this direction?
#If WinActive("ahk_exe chrome.exe") && A_Cursor = "IBeam" ; Is in Chrome and cursor is on text field
~LButton::
Click
MouseGetPos, x1
SetTimer, Check, 100
SoundBeep, 1500
KeyWait, LButton
SetTimer, Check, Off
SoundBeep, 1000
Return
#If
Check:
MouseGetPos, x2
f := Floor(Abs((x2 - x1) / 110)) ; calculate if the pointer have travel 110px
Switch
{
Case x2 > x1: Send ^+{Right %f%}
Case x2 < x1: Send % "{Right}^+{Left " f + 1 "}" ;Does not allow selecting the previous word while keeping the current word selected
}
Return

AutoHotKey determination of the image search location

the script currently works fine ... but can you append the area (xy) in which image will appear? so that he would not look around the screen?
Loop
{
ImageSearch ,,, 0 , 0 , A_ScreenWidth , A_ScreenHeight , mor.png
bT := ErrorLevel ? bT : 1
ImageSearch ,,, 0 , 0 , A_ScreenWidth , A_ScreenHeight , 2osoby.png
bT := ErrorLevel ? bT : 1
ImageSearch ,,, 0 , 0 , A_ScreenWidth , A_ScreenHeight , smiec.png
bT := ErrorLevel ? bT : 1
If bT
{
bT := 0
send {PrintScreen}
Random, x, 1190,1300
Random, y, 410, 450
MouseMove, %x%, %y%, 0
Click
Sleep , 500
} }
Return
f1::ExitApp
`::Pause
From the AHK documentation https://autohotkey.com/docs/commands/ImageSearch.htm
ImageSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ImageFile
X1,Y1 The X and Y coordinates of the upper left corner of the rectangle to search, which can be expressions. Coordinates are
relative to the active window unless CoordMode was used to change
that.

Use windows key as part of keyboard shortcut in Visual Studio 2017

I have a global hotkey (in AutoHotkey) that uses ctrl+alt+win+1, but Visual Studio 2017 registers this as ctrl+alt+1, causing a conflict between these two programs.
According to a previous question it is impossible to use # (windows) key as part of Visual Studio keyboard shortcut, but is there a way to have it not respond to commands that do use it?
It is difficult to say how to solved this, i can not see in your question what Ahk Script it is, but you can try, this on your Windows System:
1 - You can run a external Ahk Script (in the Background) [KeypressToReg.ahk] this Script can Scan All you Keyboard Movements and then put it into Only One [Windows Registry Key]
This is only a Simulation to Show you, that it Will Write the Keypress Value to a Single Register key.
2 - Then You can run Visual Studio 2017 and Look [What Value it is] if you press the key [Ctrl+Alt+Win+1]
(You can use this Ahk Script [ShowKeypressValue.ahk]) (Note - this script is only to let you see what Value it is.)
3 - Now you can Simple use that String Value "Ctrl + Alt + LWin + 1" without to must have using this ^!{LWin}1::, to execute any kind of Ahk Codes. (you can even Make a Short Script From Other Languages Like Visual Studio 2017, you only need to acces that registry key.)
loop
{
RegRead, KeypressValue, HKEY_CURRENT_USER,software\GetKeypressValue,KeypressValue ; read KeypressValue
if (KeypressValue="Ctrl + Alt + LWin + 1")
{
; Here you can put the code.
;WriteReg_KeypressValue("He it Works")
}
}
ShowKeypressValue.ahk
#SingleInstance force
Gui, +AlwaysOnTop -MaximizeBox
Gui, Add, Text, center y10 h50 w300 vVar, %KeypressValue%
Gui, Color, White
Gui, show
size=18
Gui, Font, s%size%
GuiControl, Font, var
loop
{
RegRead, KeypressValue, HKEY_CURRENT_USER,software\GetKeypressValue,KeypressValue ; read KeypressValue
if (KeypressValue="Ctrl + Alt + LWin + 1")
{
; Here you can put the code.
;WriteReg_KeypressValue("He it Works")
}
sleep 50
GuiControl,, var, %KeypressValue%
}
~esc::exitapp
WriteReg_KeypressValue(a)
{
RegWrite, REG_SZ, HKEY_CURRENT_USER,software\GetKeypressValue,KeypressValue,%a% ;Write the KeypressValue
}
[KeypressToReg.ahk]
; KeypressToReg.ahk comes from KeypressOSD.ahk By RaptorX
; The Changelog you will find it on the Bottom of the script.
;This code works with a getkeyname from a Dllcall (See Bottom Script- by Lexikos)
;you can press the esc key to exit.
#SingleInstance force
#NoEnv
SetBatchLines, -1
ListLines, Off
; Settings
global TransN := 200 ; 0~255
global ShowSingleKey := True
global ShowMouseButton := True
global ShowSingleModifierKey := True
global ShowModifierKeyCount := true
global ShowStickyModKeyCount := false
global DisplayTime := 2000 ; In milliseconds
global GuiPosition := "Bottom" ; Top or Bottom
global FontSize := 50
global GuiHeight := 115
CreateGUI()
CreateHotkey()
return
OnKeyPressed:
try {
key := GetKeyStr()
ShowHotkey(key)
SetTimer, HideGUI, % -1 * DisplayTime
}
return
OnKeyUp:
return
_OnKeyUp:
tickcount_start := A_TickCount
return
CreateGUI() {
global
Gui, +AlwaysOnTop -Caption +Owner +LastFound +E0x20
Gui, Margin, 0, 0
Gui, Color, Black
Gui, Font, cWhite s%FontSize% bold, Arial
Gui, Add, Text, vHotkeyText Center y20
WinSet, Transparent, %TransN%
}
CreateHotkey() {
Loop, 95
{
k := Chr(A_Index + 31)
k := (k = " ") ? "Space" : k
Hotkey, % "~*" k, OnKeyPressed
Hotkey, % "~*" k " Up", _OnKeyUp
}
Loop, 24 ; F1-F24
{
Hotkey, % "~*F" A_Index, OnKeyPressed
Hotkey, % "~*F" A_Index " Up", _OnKeyUp
}
Loop, 10 ; Numpad0 - Numpad9
{
Hotkey, % "~*Numpad" A_Index - 1, OnKeyPressed
Hotkey, % "~*Numpad" A_Index - 1 " Up", _OnKeyUp
}
Otherkeys := "WheelDown|WheelUp|WheelLeft|WheelRight|XButton1|XButton2|Browser_Forward|Browser_Back|Browser_Refresh|Browser_Stop|Browser_Search|Browser_Favorites|Browser_Home|Volume_Mute|Volume_Down|Volume_Up|Media_Next|Media_Prev|Media_Stop|Media_Play_Pause|Launch_Mail|Launch_Media|Launch_App1|Launch_App2|Help|Sleep|PrintScreen|CtrlBreak|Break|AppsKey|NumpadDot|NumpadDiv|NumpadMult|NumpadAdd|NumpadSub|NumpadEnter|Tab|Enter|Esc|BackSpace"
. "|Del|Insert|Home|End|PgUp|PgDn|Up|Down|Left|Right|ScrollLock|CapsLock|NumLock|Pause|sc145|sc146|sc046|sc123"
Loop, parse, Otherkeys, |
{
Hotkey, % "~*" A_LoopField, OnKeyPressed
Hotkey, % "~*" A_LoopField " Up", _OnKeyUp
}
If ShowMouseButton {
Loop, Parse, % "LButton|MButton|RButton", |
Hotkey, % "~*" A_LoopField, OnKeyPressed
}
for i, mod in ["Ctrl", "Shift", "Alt"] {
Hotkey, % "~*" mod, OnKeyPressed
Hotkey, % "~*" mod " Up", OnKeyUp
}
for i, mod in ["LWin", "RWin"]
Hotkey, % "~*" mod, OnKeyPressed
}
ShowHotkey(HotkeyStr) {
WinGetPos, ActWin_X, ActWin_Y, ActWin_W, ActWin_H, A
if !ActWin_W
throw
text_w := (ActWin_W > A_ScreenWidth) ? A_ScreenWidth : ActWin_W
;GuiControl, , HotkeyText, %HotkeyStr%
;GuiControl, Move, HotkeyText, w%text_w% Center
RegWrite, REG_SZ, HKEY_CURRENT_USER,software\GetKeypressValue,KeypressValue,%HotkeyStr%
if (GuiPosition = "Top")
gui_y := ActWin_Y
else
gui_y := (ActWin_Y+ActWin_H) - 115 - 50
;Gui, Show, NoActivate x%ActWin_X% y%gui_y% h%GuiHeight% w%text_w%
}
GetKeyStr() {
static modifiers := ["Ctrl", "Shift", "Alt", "LWin", "RWin"]
static repeatCount := 1
for i, mod in modifiers {
if GetKeyState(mod)
prefix .= mod " + "
}
if (!prefix && !ShowSingleKey)
throw
key := SubStr(A_ThisHotkey, 3)
if (key ~= "i)^(Ctrl|Shift|Alt|LWin|RWin)$") {
if !ShowSingleModifierKey {
throw
}
key := ""
prefix := RTrim(prefix, "+ ")
if ShowModifierKeyCount {
if !InStr(prefix, "+") && IsDoubleClickEx() {
if (A_ThisHotKey != A_PriorHotKey) || ShowStickyModKeyCount {
if (++repeatCount > 1) {
prefix .= " ( * " repeatCount " )"
}
} else {
repeatCount := 0
}
} else {
repeatCount := 1
}
}
} else {
if ( StrLen(key) = 1 ) {
key := GetKeyChar(key, "A")
} else if ( SubStr(key, 1, 2) = "sc" ) {
key := SpecialSC(key)
} else if (key = "LButton") && IsDoubleClick() {
key := "Double-Click"
}
_key := (key = "Double-Click") ? "LButton" : key
static pre_prefix, pre_key, keyCount := 1
global tickcount_start
if (prefix && pre_prefix) && (A_TickCount-tickcount_start < 300) {
if (prefix != pre_prefix) {
result := pre_prefix pre_key ", " prefix key
} else {
keyCount := (key=pre_key) ? (keyCount+1) : 1
key := (keyCount>2) ? (key " (" keyCount ")") : (pre_key ", " key)
}
} else {
keyCount := 1
}
pre_prefix := prefix
pre_key := _key
repeatCount := 1
}
return result ? result : prefix . key
}
SpecialSC(sc) {
static k := {sc046: "ScrollLock", sc145: "NumLock", sc146: "Pause", sc123: "Genius LuxeMate Scroll"}
return k[sc]
}
; by Lexikos - https://autohotkey.com/board/topic/110808-getkeyname-for-other-languages/#entry682236
GetKeyChar(Key, WinTitle:=0) {
thread := WinTitle=0 ? 0
: DllCall("GetWindowThreadProcessId", "ptr", WinExist(WinTitle), "ptr", 0)
hkl := DllCall("GetKeyboardLayout", "uint", thread, "ptr")
vk := GetKeyVK(Key), sc := GetKeySC(Key)
VarSetCapacity(state, 256, 0)
VarSetCapacity(char, 4, 0)
n := DllCall("ToUnicodeEx", "uint", vk, "uint", sc
, "ptr", &state, "ptr", &char, "int", 2, "uint", 0, "ptr", hkl)
return StrGet(&char, n, "utf-16")
}
IsDoubleClick(MSec = 300) {
Return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey < MSec)
}
IsDoubleClickEx(MSec = 300) {
preHotkey := RegExReplace(A_PriorHotkey, "i) Up$")
Return (A_ThisHotKey = preHotkey) && (A_TimeSincePriorHotkey < MSec)
}
HideGUI() {
Gui, Hide
}
esc::exitapp
;---------------------------------------------
; ChangeLog : v2.22 (2017-02-25) - Now pressing the same combination keys continuously more than 2 times,
; for example press Ctrl+V 3 times, will displayed as "Ctrl + v (3)"
; v2.21 (2017-02-24) - Fixed LWin/RWin not poping up start menu
; v2.20 (2017-02-24) - Added displaying continuous-pressed combination keys.
; e.g.: With CTRL key held down, pressing K and U continuously will shown as "Ctrl + k, u"
; v2.10 (2017-01-22) - Added ShowStickyModKeyCount option
; v2.09 (2017-01-22) - Added ShowModifierKeyCount option
; v2.08 (2017-01-19) - Fixed a bug
; v2.07 (2017-01-19) - Added ShowSingleModifierKey option (default is True)
; v2.06 (2016-11-23) - Added more keys. Thanks to SashaChernykh.
; v2.05 (2016-10-01) - Fixed not detecting "Ctrl + ScrollLock/NumLock/Pause". Thanks to lexikos.
; v2.04 (2016-10-01) - Added NumpadDot and AppsKey
; v2.03 (2016-09-17) - Added displaying "Double-Click" of the left mouse button.
; v2.02 (2016-09-16) - Added displaying mouse button, and 3 settings (ShowMouseButton, FontSize, GuiHeight)
; v2.01 (2016-09-11) - Display non english keyboard layout characters when combine with modifer keys.
; v2.00 (2016-09-01) - Removed the "Fade out" effect because of its buggy.
; - Added support for non english keyboard layout.
; - Added GuiPosition setting.
; v1.00 (2013-10-11) - First release.
;--------------------------------------------

Autohotkey Fullscreening With Cmd.exe

Using ahk, what script can I use to fullscreen cmd on windows 7?
I have already managed to fullscreen with windows 10, but on windows 7 it looks like this.
However you can see the on the top and left side there are borders, I am using the following script.
WinGetTitle, currentWindow, A
IfWinExist %currentWindow%
{
WinSet, Style, ^0xC00000 ; toggle title bar
}
return
What can I do to make it work?
Perhaps you need to remove the border?
Try this:
/* YABT+ - Yet Another Borderless-Window Toggle
* by Barrow (March 30, 2012)
* rewritten by kon (May 16, 2014)
* http://www.autohotkey.com/board/topic/78903-yabt-yet-another-borderless-window-toggle/page-2#entry650488
* updated by Hastarin (Dec 5, 2014)
* updated by WAZAAAAA (Sep 27, 2016)
* tested with AutoHotkey v1.1.24.01
*/
WinGetTitle, currentWindow, A
IfWinExist %currentWindow%
{
Toggle_Window(WinExist(currentWindow))
}
Toggle_Window(Window:="") {
static A := Init()
if (!Window)
MouseGetPos,,, Window
WinGet, S, Style, % (i := "_" Window) ? "ahk_id " Window : ; Get window style
if (S & +0xC00000) { ; If not borderless
WinGet, IsMaxed, MinMax, % "ahk_id " Window
if (A[i, "Maxed"] := IsMaxed = 1 ? true : false)
WinRestore, % "ahk_id " Window
WinGetPos, X, Y, W, H, % "ahk_id " Window ; Store window size/location
for k, v in ["X", "Y", "W", "H"]
A[i, v] := %v%
Loop, % A.MCount { ; Determine which monitor to use
if (X >= A.Monitor[A_Index].Left
&& X < A.Monitor[A_Index].Right
&& Y >= A.Monitor[A_Index].Top
&& Y < A.Monitor[A_Index].Bottom) {
WinSet, Style, -0xC00000, % "ahk_id " Window ; Remove borders
WinSet, Style, -0x40000, % "ahk_id " Window ; Including the resize border
WinSet, ExStyle, -0x00000200, % "ahk_id " Window ;Also WS_EX_CLIENTEDGE
; The following lines are the x,y,w,h of the maximized window
; ie. to offset the window 10 pixels up: A.Monitor[A_Index].Top - 10
WinMove, % "ahk_id " Window,
, A.Monitor[A_Index].Left ; X position
, A.Monitor[A_Index].Top ; Y position
, A.Monitor[A_Index].Right - A.Monitor[A_Index].Left ; Width
, A.Monitor[A_Index].Bottom - A.Monitor[A_Index].Top ; Height
break
}
}
}
else if (S & -0xC00000) { ; If borderless
WinSet, Style, +0x40000, % "ahk_id " Window ; Reapply borders
WinSet, Style, +0xC00000, % "ahk_id " Window
WinSet, ExStyle, +0x00000200, % "ahk_id " Window ;Also WS_EX_CLIENTEDGE
WinMove, % "ahk_id " Window,, A[i].X, A[i].Y, A[i].W, A[i].H ; Return to original position
if (A[i].Maxed)
WinMaximize, % "ahk_id " Window
A.Remove(i)
}
}
Init() {
A := {}
SysGet, n, MonitorCount
Loop, % A.MCount := n {
SysGet, Mon, Monitor, % i := A_Index
for k, v in ["Left", "Right", "Top", "Bottom"]
A["Monitor", i, v] := Mon%v%
}
return A
}

Resources