OSD Mouse Location and Cross Hair in same script issue... Topic is solved

Ask gaming related questions (AHK v1.1 and older)
User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 04 Aug 2022, 20:09

Would someone help me out with my code and tell me what I have done wrong?
Everything seems to work, but they seem to conflict with each other and can end
up in the same location, but never can they turn on at the same time.

I would like to have two hotkeys, one for Cross hair and the other for Mouse Location.
I was able to get them both to show and work, but a little bit off..

Thank you for taking a look at my work. I am a bit new.. Take care!

Code: Select all

#NoEnv
#InstallKeybdHook
#UseHook On
#SingleInstance force ;only one instance of this script may run at a time!
#MaxHotkeysPerInterval 200
#WinActivateForce ;https://autohotkey.com/docs/commands/_WinActivateForce.htm
DetectHiddenWindows, On
SetWorkingDir %A_ScriptDir%
SendMode Input
CoordMode, Mouse, Screen ; mouse coordinates relative to the screen

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; CrossHair made with OSD
F3::
mYcR1 = X
jtcr:=!jtcr ; Toggle
if jtcr
{
CustomColor := "3F0EFF"  ; Can be any RGB color (it will be made transparent below).
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor%
Gui, Font, s20 q3 ; Set a large font size (32-point).
Gui, Add, Text, vMyText3 cBlue, XXXXX YYYYY ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSet, TransColor, %CustomColor% 150
SetTimer, UpdateOSD, 200
Gosub, UpdateOSD  ; Make the first update immediate rather than waiting for the timer.
Gui, Show, x924 y508 NoActivate  ; NoActivate avoids deactivating the currently active window.
return

UpdateOSD:
GuiControl,, MyText3, %mYcR1%
return
} else {
 Gui Destroy
}
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Creates an On-screen display (OSD) via transparent window.
F4::
m1Tex = Mouse
m2Tex = Location
s1pace = y+0
josdf4:=!josdf4 ; Toggle
if josdf4
{
CustomColor1 := "3F0EFF"  ; Can be any RGB color (it will be made transparent below).
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor1%
Gui, Font, s9 q3 ; Set a large font size (32-point).
Gui, Add, Text, vMyText cGray, XXXXX YYYYY ; XX & YY serve to auto-size the window.
Gui, Add, Text, %s1pace% vMyText1 cGray, XXXXX YYYYY
Gui, Add, Text, %s1pace% vMyText2 cGray, XXXXX YYYYY
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSet, TransColor, %CustomColor1% 150
SetTimer, UpdateOSD1, 200
Gosub, UpdateOSD1  ; Make the first update immediate rather than waiting for the timer.
Gui, Show, x185 y925 NoActivate  ; NoActivate avoids deactivating the currently active window.
return

UpdateOSD1:
MouseGetPos, MouseX, MouseY
GuiControl,, MyText, %m1Tex%
GuiControl,, MyText1, X%MouseX%, Y%MouseY%
GuiControl,, MyText2, %m2Tex%
return
} else {
 Gui Destroy
}
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[Mode action: Moved topic to “Gaming”]

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: OSD Mouse Location and Cross Hair in same script issue...  Topic is solved

Post by Rohwedder » 05 Aug 2022, 05:03

Hallo, try:

Code: Select all

#NoEnv
#InstallKeybdHook
#UseHook On
#SingleInstance force ;only one instance of this script may run at a time!
#MaxHotkeysPerInterval 200
#WinActivateForce ;https://autohotkey.com/docs/commands/_WinActivateForce.htm
DetectHiddenWindows, On
SetWorkingDir %A_ScriptDir%
SendMode Input
CoordMode, Mouse, Screen ; mouse coordinates relative to the screen
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; CrossHair made with OSD
F3::
mYcR1 = X
jtcr:=!jtcr ; Toggle
if jtcr
{
	CustomColor := "3F0EFF"  ; Can be any RGB color (it will be made transparent below).
	Gui, 2: +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
	Gui, 2: Color, %CustomColor%
	Gui, 2: Font, s20 q3 ; Set a large font size (32-point).
	Gui, 2: Add, Text, vMyText3 cBlue, XXXXX YYYYY ; XX & YY serve to auto-size the window.
	; Make all pixels of this color transparent and make the text itself translucent (150):
	WinSet, TransColor, %CustomColor% 150
	SetTimer, UpdateOSD, 200
	Gosub, UpdateOSD  ; Make the first update immediate rather than waiting for the timer.
	Gui, 2: Show, x924 y508 NoActivate  ; NoActivate avoids deactivating the currently active window.
	return
	UpdateOSD:
	GuiControl,2:, MyText3, %mYcR1%
	return
}
else
{
	Gui, 2: Destroy
	SetTimer, UpdateOSD, Off
}
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Creates an On-screen display (OSD) via transparent window.
F4::
m1Tex = Mouse
m2Tex = Location
s1pace = y+0
josdf4:=!josdf4 ; Toggle
if josdf4
{
	CustomColor1 := "3F0EFF"  ; Can be any RGB color (it will be made transparent below).
	Gui +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
	Gui, Color, %CustomColor1%
	Gui, Font, s9 q3 ; Set a large font size (32-point).
	Gui, Add, Text, vMyText cGray, XXXXX YYYYY ; XX & YY serve to auto-size the window.
	Gui, Add, Text, %s1pace% vMyText1 cGray, XXXXX YYYYY
	Gui, Add, Text, %s1pace% vMyText2 cGray, XXXXX YYYYY
	; Make all pixels of this color transparent and make the text itself translucent (150):
	WinSet, TransColor, %CustomColor1% 150
	SetTimer, UpdateOSD1, 200
	Gosub, UpdateOSD1  ; Make the first update immediate rather than waiting for the timer.
	Gui, Show, x185 y925 NoActivate  ; NoActivate avoids deactivating the currently active window.
	return
	UpdateOSD1:
	MouseGetPos, MouseX, MouseY
	GuiControl,, MyText, %m1Tex%
	GuiControl,, MyText1, X%MouseX%, Y%MouseY%
	GuiControl,, MyText2, %m2Tex%
	return
}
else
{
	Gui Destroy
	SetTimer, UpdateOSD1, Off
}
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you don't give a Gui a name, it gets the name 1.
Since you can't have two Guis with name 1 in one script at the same time, I gave one Gui the name 2.

User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 05 Aug 2022, 13:59

You are wonderful! :D Working great!... :bravo: I was trying to add that before and then the code didnt work at all, so I thought I would ask. I forgot a couple of commas when I did it.. Now I know what I did wrong and you are wonderful! :dance:

This works as a cross hair in any game, but you need to off set the position of the letter "X" to the middle of your screen.

I use it right now for Call Of Duty Warzone! Its great knowing the center of your screen, so you can no scope perfectly! :clap:

User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 05 Aug 2022, 16:35

@Rohwedder

Hey, sorry to bother you, but would you check this code and let me know how to make the BE RIGHT BACK in the middle of the Blue Back Ground?

Thank you for everything!

Code: Select all


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Be Right Back made with OSD
F2::
s2pace = y+0
mYBRB1 = BE RIGHT BACK
jtBRB:=!jtBRB ; Toggle
if jtBRB
{
CustomColor2 := "3F0EFF"  ; Can be any RGB color (it will be made transparent below).
Gui, 3: +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, 3: Color, %CustomColor2%
Gui, 3: Font, s45 q3 ; Set a large font size (32-point).
Gui, 3: Add, Text, %s2pace% vMyText4 cRed, XXXXX YYYYY GGGGG ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
;WinSet, TransColor, %CustomColor2% 150
SetTimer, UpdateOSD3, 200
Gosub, UpdateOSD3  ; Make the first update immediate rather than waiting for the timer.
Gui, 3: Show, x135 y400 NoActivate  ; NoActivate avoids deactivating the currently active window.
return

UpdateOSD3:
GuiControl,3:, MyText4, %mYBRB1%
return
} else {
 Gui, 3: Destroy
 SetTimer, UpdateOSD3, Off
}
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Rohwedder » 06 Aug 2022, 01:48

Replace:

Code: Select all

s2pace = y+0
by:

Code: Select all

s2pace = Center
Just out of interest: Why do you use a timer that updates a static text every 200 ms? Everyone has the right to do nonsensical things, but isn't this too nonsensical? (Even letter "X" is static text.)

User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 06 Aug 2022, 02:20

Rohwedder wrote:
06 Aug 2022, 01:48
Replace:

Code: Select all

s2pace = y+0
by:

Code: Select all

s2pace = Center
Just out of interest: Why do you use a timer that updates a static text every 200 ms? Everyone has the right to do nonsensical things, but isn't this too nonsensical? (Even letter "X" is static text.)
Thank you for the quick reply. Center worked great!

I am not sure about the Static text every 200 ms.. I believe that was only for the Mouse Position..

Should I remove it for the text "X" and "Be Right Back"? I am still a bit new to this, but its fun!

Thanks again!

-Justin

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Rohwedder » 06 Aug 2022, 02:56

"Be Right Back" without Timer:

Code: Select all

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Be Right Back made with OSD
F2::
s2pace = Center
mYBRB1 = BE RIGHT BACK
if jtBRB := !jtBRB ; Toggle
{
	CustomColor2 := "3F0EFF"  ; Can be any RGB color (it will be made transparent below).
	Gui, 3: +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
	Gui, 3: Color, %CustomColor2%
	Gui, 3: Font, s45 q3 ; Set a large font size (32-point).
	Gui, 3: Add, Text, %s2pace% vMyText4 cRed, %mYBRB1%
	; Make all pixels of this color transparent and make the text itself translucent (150):
	;WinSet, TransColor, %CustomColor2% 150
	Gui, 3: Show, x135 y400 NoActivate  ; NoActivate avoids deactivating the currently active window.
} else Gui, 3: Destroy
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 06 Aug 2022, 05:00

Wonderful! That works sweet! You are great!

Next question I would have is how to space Up/Down or Left/Right with the Text?

I am having a hard time with that..

Code now
_____________
Mouse
Location
X0000 Y0000
_____________

to: Code when fixed

______________
------Mouse-----
-----Location----
--X0000 Y0000--
______________

Without the Minus signs.. I would like spaces in there..

And also keep the spacing Up/Down very small.

Any help with that would be great! Thank you!

-Justin

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Rohwedder » 06 Aug 2022, 07:49

Then try:

Code: Select all

#NoEnv
#InstallKeybdHook
#UseHook On
#SingleInstance force ;only one instance of this script may run at a time!
#MaxHotkeysPerInterval 200
#WinActivateForce ;https://autohotkey.com/docs/commands/_WinActivateForce.htm
DetectHiddenWindows, On
SetWorkingDir %A_ScriptDir%
SendMode Input
CoordMode, Mouse, Screen ; mouse coordinates relative to the screen
; Creates an On-screen display (OSD) via transparent window.
F4::
m1Tex = Mouse
m2Tex = Location
s1pace = Center y+-2
if josdf4:=!josdf4 ; Toggle
{
	CustomColor1 := "3F0EFF"  ; Can be any RGB color (it will be made transparent below).
	Gui +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
	Gui, Color, %CustomColor1%
	Gui, Font, s9 q3 ; Set a large font size (32-point).
	Gui, Add, Text, Center %s1pace% vMyText cGray, XXXXX YYYYY ; XX & YY serve to auto-size the window.
	Gui, Add, Text, Center %s1pace% vMyText1 cGray, XXXXX YYYYY
	Gui, Add, Text, Center %s1pace% vMyText2 cGray, XXXXX YYYYY
	; Make all pixels of this color transparent and make the text itself translucent (150):
	WinSet, TransColor, %CustomColor1% 150
	SetTimer, UpdateOSD1, 200
	Gosub, UpdateOSD1  ; Make the first update immediate rather than waiting for the timer.
	Gui, Show, x185 y925 NoActivate  ; NoActivate avoids deactivating the currently active window.
	return
	UpdateOSD1:
	MouseGetPos, MouseX, MouseY
	GuiControl,, MyText, %m1Tex%
	GuiControl,, MyText1, X%MouseX%, Y%MouseY%
	GuiControl,, MyText2, %m2Tex%
	return
}
else
{
	Gui Destroy
	SetTimer, UpdateOSD1, Off
}
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 06 Aug 2022, 20:39

Rohwedder wrote:
06 Aug 2022, 07:49
Then try:

Code: Select all

#NoEnv
#InstallKeybdHook
#UseHook On
#SingleInstance force ;only one instance of this script may run at a time!
#MaxHotkeysPerInterval 200
#WinActivateForce ;https://autohotkey.com/docs/commands/_WinActivateForce.htm
DetectHiddenWindows, On
SetWorkingDir %A_ScriptDir%
SendMode Input
CoordMode, Mouse, Screen ; mouse coordinates relative to the screen
; Creates an On-screen display (OSD) via transparent window.
F4::
m1Tex = Mouse
m2Tex = Location
s1pace = Center y+-2
if josdf4:=!josdf4 ; Toggle
{
	CustomColor1 := "3F0EFF"  ; Can be any RGB color (it will be made transparent below).
	Gui +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
	Gui, Color, %CustomColor1%
	Gui, Font, s9 q3 ; Set a large font size (32-point).
	Gui, Add, Text, Center %s1pace% vMyText cGray, XXXXX YYYYY ; XX & YY serve to auto-size the window.
	Gui, Add, Text, Center %s1pace% vMyText1 cGray, XXXXX YYYYY
	Gui, Add, Text, Center %s1pace% vMyText2 cGray, XXXXX YYYYY
	; Make all pixels of this color transparent and make the text itself translucent (150):
	WinSet, TransColor, %CustomColor1% 150
	SetTimer, UpdateOSD1, 200
	Gosub, UpdateOSD1  ; Make the first update immediate rather than waiting for the timer.
	Gui, Show, x185 y925 NoActivate  ; NoActivate avoids deactivating the currently active window.
	return
	UpdateOSD1:
	MouseGetPos, MouseX, MouseY
	GuiControl,, MyText, %m1Tex%
	GuiControl,, MyText1, X%MouseX%, Y%MouseY%
	GuiControl,, MyText2, %m2Tex%
	return
}
else
{
	Gui Destroy
	SetTimer, UpdateOSD1, Off
}
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is perfect! You have been so kind to me. I will not forget this! Thank you!

This completes what I was focusing on and now I can move on to something else!

Peace be with you and God bless!

-Justin

P.S.

My Code with all the fixes..

Code: Select all

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Be Right Back made with OSD
F2::
s2pace = Center
mYBRB1 =  ----- BE RIGHT BACK -----
if jtBRB := !jtBRB ; Toggle
{
CustomColor2 := "202466"  ; Can be any RGB color (it will be made transparent below).
Gui, 3: +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, 3: Color, %CustomColor2%
Gui, 3: Font, s65 q3 ; Set a large font size (32-point).
Gui, 3: Add, Text, %s2pace% vMyText4 cRed, %mYBRB1%
; Make all pixels of this color transparent and make the text itself translucent (150):
;WinSet, TransColor, %CustomColor2% 150
Gui, 3: Show, x420 y375 NoActivate  ; NoActivate avoids deactivating the currently active window.
} else Gui, 3: Destroy
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; CrossHair made with OSD
F3::
mYcR1 = X
if jtcr := !jtcr ; Toggle
{
CustomColor := "202466"  ; Can be any RGB color (it will be made transparent below).
Gui, 2: +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, 2: Color, %CustomColor%
Gui, 2: Font, s20 q3 ; Set a large font size (32-point).
Gui, 2: Add, Text, vMyText3 cBlue,  %mYcR1%
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSet, TransColor, %CustomColor% 150
Gui, 2: Show, x924 y508 NoActivate  ; NoActivate avoids deactivating the currently active window.
} else Gui, 2: Destroy
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Creates an On-screen display (OSD) via transparent window.
F4::
m1Tex = -        Mouse         -
m2Tex = -       Location       -
s1pace1 = Center y+-2
if josdf4 := !josdf4 ; Toggle
{
CustomColor1 := "202466"  ; Can be any RGB color (it will be made transparent below).
Gui, +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor1%
Gui, Font, s12 q3; Set a large font size (32-point).
Gui, Add, Text, Center %s1pace1% vMyText1 cYellow, XXXXXX YYYYYY
Gui, Add, Text, Center %s1pace1% vMyText2 cYellow, XXXXXX YYYYYY
Gui, Add, Text, Center %s1pace1% vMyText cYellow, XXXXXXX YYYYYYY ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSet, TransColor, %CustomColor1% 150
SetTimer, UpdateOSD1, 200
Gosub, UpdateOSD1  ; Make the first update immediate rather than waiting for the timer.
Gui, Show, x185 y925 NoActivate  ; NoActivate avoids deactivating the currently active window.
DllCall("SetCursorPos", int, 958, int, 540)
return
UpdateOSD1:
MouseGetPos, MouseX, MouseY
GuiControl,, MyText1, %m1Tex%
GuiControl,, MyText2, %m2Tex%
GuiControl,, MyText, (X)|%MouseX%|, (Y)|%MouseY%|
return
} else
 Gui Destroy
 SetTimer, UpdateOSD1, Off
DllCall("SetCursorPos", int, 958, int, 540)
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Show/Hide Desktop Icons with Windows+D(Removes Show Desktop(Win+D))
F5::
ControlGet, hWnd, Hwnd,, SysListView321, ahk_class Progman
if (hWnd = "")
{
    ; Here is the trick: 
    ; if you press Win+D, then `ControlGet` fails to get the hWnd,
    ; but a MsgBox can do the trick. I don't know why, but it works!
    ; Let me know if you know why. Thanks!
    MsgBox, 0, "",  "", 0.001
    ControlGet, hWnd, Hwnd,, SysListView321, ahk_class Progman
}

; Toggle between displaying and hiding the desktop icons
if DllCall("IsWindowVisible", UInt, hWnd)
{
    WinHide, ahk_id %hWnd%
} else
    WinShow, ahk_id %hWnd%
return ;<--- DO NOT DELETE **xkjtx**
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Move the Task bar 
F9::TaskbarMove("Top")
F10::TaskbarMove("Bottom")
F11::TaskbarMove("Left")
F12::TaskbarMove("Right")
TaskbarMove(p_pos) {
label:="TaskbarMove_" p_pos
WinExist("ahk_class Shell_TrayWnd")
SysGet, s, Monitor
if (IsLabel(label)) {
Goto, %label%
}
return
TaskbarMove_Top:
TaskbarMove_Bottom:
WinMove(sLeft, s%p_pos%, sRight, 0)
return
TaskbarMove_Left:
TaskbarMove_Right:
WinMove(s%p_pos%, sTop, 0, sBottom)
return
}
WinMove(p_x, p_y, p_w="", p_h="", p_hwnd="") {
WM_ENTERSIZEMOVE:=0x0231
WM_EXITSIZEMOVE :=0x0232
if (p_hwnd!="") {
WinExist("ahk_id " p_hwnd)
}
SendMessage, WM_ENTERSIZEMOVE
;//Tooltip WinMove(%p_x%`, %p_y%`, %p_w%`, %p_h%)
WinMove, , , p_x, p_y, p_w, p_h
SendMessage, WM_EXITSIZEMOVE
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 07 Aug 2022, 02:06

@Rohwedder

I got another one for you, good sir! How about Font Styles?

Where do I add the Font Styles to my code?

I would like to change the Font Style to something like "ORGANICAL Font"

From this site here https://www.fontspace.com/organical-font-f74000

I have already installed the Font, but need to understand how to add it to the code?

Thanks again for everything! I am having so much fun!

-Justin

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Rohwedder » 07 Aug 2022, 02:26

To get the ID of Progman SysListView321, I suggest to start the script with this:

Code: Select all

ControlGet, SysListView321, Hwnd,, SysListView321, ahk_class Progman
IF !SysListView321
{ ; if you press Win+D, then `ControlGet` fails to get the hWnd
	Send, #d
	Sleep, 1000
	ControlGet, SysListView321, Hwnd,, SysListView321, ahk_class Progman
	Send, #d
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Show/Hide Desktop Icons with Windows+D(Removes Show Desktop(Win+D))
F5:: ; Toggle between displaying and hiding the desktop icons
if DllCall("IsWindowVisible", UInt, SysListView321)
	WinHide, ahk_id %SysListView321%
else
	WinShow, ahk_id %SysListView321%
return
A msgbox makes Windows forget the window selection before the applied Win+D.

User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 07 Aug 2022, 18:22

Rohwedder wrote:
07 Aug 2022, 02:26
To get the ID of Progman SysListView321, I suggest to start the script with this:

Code: Select all

ControlGet, SysListView321, Hwnd,, SysListView321, ahk_class Progman
IF !SysListView321
{ ; if you press Win+D, then `ControlGet` fails to get the hWnd
	Send, #d
	Sleep, 1000
	ControlGet, SysListView321, Hwnd,, SysListView321, ahk_class Progman
	Send, #d
}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Show/Hide Desktop Icons with Windows+D(Removes Show Desktop(Win+D))
F5:: ; Toggle between displaying and hiding the desktop icons
if DllCall("IsWindowVisible", UInt, SysListView321)
	WinHide, ahk_id %SysListView321%
else
	WinShow, ahk_id %SysListView321%
return
A msgbox makes Windows forget the window selection before the applied Win+D.
Wonderful Option and it does work well for keeping both actions alive..
I do not like Show Desktop with Win+D, so that is the main reason I did it.
I also changed F1(Windows Help) to open both Sound Options for switching
sound devices.. Its nice running my own shortcuts and not have to
deal with Windows ones..

Great work!

User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 07 Aug 2022, 18:32

I have switched to this code down below, for my Hide/Show desktop icons.

This code really does check and uncheck the Right click menu option
for hide and show icons.. It has a delay, so you have to wait just a min for the
icons to reappear, but that is the same way if you did it through the right click
menu..

Code: Select all

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Show/Hide Desktop Icons with WindowsKey+D)
DesktopIcons( Show:=-1 )                  ; By SKAN for ahk/ah2 on D35D/D495 @ tiny.cc/desktopicons
{
    Local hProgman := WinExist("ahk_class WorkerW", "FolderView") ? WinExist()
                   :  WinExist("ahk_class Progman", "FolderView")

    Local hShellDefView := DllCall("user32.dll\GetWindow", "ptr",hProgman,      "int",5, "ptr")
    Local hSysListView  := DllCall("user32.dll\GetWindow", "ptr",hShellDefView, "int",5, "ptr")

    If ( DllCall("user32.dll\IsWindowVisible", "ptr",hSysListView) != Show )
         DllCall("user32.dll\SendMessage", "ptr",hShellDefView, "ptr",0x111, "ptr",0x7402, "ptr",0)
}
#d::
DesktopIcons()
Return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Rohwedder » 08 Aug 2022, 04:22

Just for fun with acoustic feedback:

Code: Select all

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Show/Hide Desktop Icons with WindowsKey+D)
DesktopIcons( Show:=-1 )                  ; By SKAN for ahk/ah2 on D35D/D495 @ tiny.cc/desktopicons
{
    Local hProgman := WinExist("ahk_class WorkerW", "FolderView") ? WinExist()
                   :  WinExist("ahk_class Progman", "FolderView")

    Local hShellDefView := DllCall("user32.dll\GetWindow", "ptr",hProgman,      "int",5, "ptr")
    Local hSysListView  := DllCall("user32.dll\GetWindow", "ptr",hShellDefView, "int",5, "ptr")

    If ( Show != Hidden := DllCall("user32.dll\IsWindowVisible", "ptr",hSysListView) )
         DllCall("user32.dll\SendMessage", "ptr",hShellDefView, "ptr",0x111, "ptr",0x7402, "ptr",0)
	Return Hidden
}
#d::
ComObjCreate("SAPI.SpVoice").Speak(DesktopIcons()?"Icons hiddens":"Icons reappears")
Return ;AutoHotkey v2: ComObject("SAPI.SpVoice")
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 08 Aug 2022, 22:44

Rohwedder wrote:
08 Aug 2022, 04:22
Just for fun with acoustic feedback:

Code: Select all

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Show/Hide Desktop Icons with WindowsKey+D)
DesktopIcons( Show:=-1 )                  ; By SKAN for ahk/ah2 on D35D/D495 @ tiny.cc/desktopicons
{
    Local hProgman := WinExist("ahk_class WorkerW", "FolderView") ? WinExist()
                   :  WinExist("ahk_class Progman", "FolderView")

    Local hShellDefView := DllCall("user32.dll\GetWindow", "ptr",hProgman,      "int",5, "ptr")
    Local hSysListView  := DllCall("user32.dll\GetWindow", "ptr",hShellDefView, "int",5, "ptr")

    If ( Show != Hidden := DllCall("user32.dll\IsWindowVisible", "ptr",hSysListView) )
         DllCall("user32.dll\SendMessage", "ptr",hShellDefView, "ptr",0x111, "ptr",0x7402, "ptr",0)
	Return Hidden
}
#d::
ComObjCreate("SAPI.SpVoice").Speak(DesktopIcons()?"Icons hiddens":"Icons reappears")
Return ;AutoHotkey v2: ComObject("SAPI.SpVoice")
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dude! I love it and I am adding it right now! You are great! If I have any more questions, I will be sure to ask!

You have a great day!

-Justin

P.S. where do I get more voices and how do I add the new voices to this code? Wonderful job!

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Rohwedder » 09 Aug 2022, 04:01

This is what I have collected about ComObjCreate("SAPI.SpVoice"):

Code: Select all

; "SAPI" be my name for this object
SAPI := ComObjCreate("SAPI.SpVoice")
;AutoHotkey v2: SAPI := ComObject("SAPI.SpVoice")
MsgBox,% "Rate: " SAPI.Rate ; gets and sets the 
SAPI.Rate := -2 ; speaking rate (=speed), range: -10 - 10
MsgBox,% "Volume: " SAPI.Volume ; gets and sets the
SAPI.Volume := 90 ;  ; speaking volume, range: 0 - 100
Pitch := 4 ; sets the speaking pitch, range: -10 - 10
SAPI.Speak("<Pitch AbsMiddle=""" Pitch """/>", 0x29)
MsgBox,% "Voice: " SAPI.Voice.GetAttribute("Name")
; gets the name of the current voice (here: Microsoft Hedda Desktop)
MsgBox,% "Number: " SAPI.GetVoices.Count
; gets the voices number (here: 3)
For No In SAPI.GetVoices
    Voices .= A_Index-1 " = " No.GetDescription "`n"
; Numbers, names and descriptions of the voices
InputBox, No, Voices,% Voices,,,,,,,, 0
SAPI.Voice := SAPI.GetVoices().Item(No)
; sets the current voice, range of No : 0 - Number-1
SAPI.Speak("Hello World")
SoundBeep, 1000, 1000 ;first Speak then Beep
Sleep, 1000 
SAPI.Speak("Hello World", True)
; with FlagsAsync = True the script's current thread will
; move on to the next command(s) while speaking
SoundBeep, 2000, 1000 ;Speak and Beep at the same time

User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 09 Aug 2022, 20:12

Rohwedder wrote:
09 Aug 2022, 04:01
This is what I have collected about ComObjCreate("SAPI.SpVoice"):

Code: Select all

; "SAPI" be my name for this object
SAPI := ComObjCreate("SAPI.SpVoice")
;AutoHotkey v2: SAPI := ComObject("SAPI.SpVoice")
MsgBox,% "Rate: " SAPI.Rate ; gets and sets the 
SAPI.Rate := -2 ; speaking rate (=speed), range: -10 - 10
MsgBox,% "Volume: " SAPI.Volume ; gets and sets the
SAPI.Volume := 90 ;  ; speaking volume, range: 0 - 100
Pitch := 4 ; sets the speaking pitch, range: -10 - 10
SAPI.Speak("<Pitch AbsMiddle=""" Pitch """/>", 0x29)
MsgBox,% "Voice: " SAPI.Voice.GetAttribute("Name")
; gets the name of the current voice (here: Microsoft Hedda Desktop)
MsgBox,% "Number: " SAPI.GetVoices.Count
; gets the voices number (here: 3)
For No In SAPI.GetVoices
    Voices .= A_Index-1 " = " No.GetDescription "`n"
; Numbers, names and descriptions of the voices
InputBox, No, Voices,% Voices,,,,,,,, 0
SAPI.Voice := SAPI.GetVoices().Item(No)
; sets the current voice, range of No : 0 - Number-1
SAPI.Speak("Hello World")
SoundBeep, 1000, 1000 ;first Speak then Beep
Sleep, 1000 
SAPI.Speak("Hello World", True)
; with FlagsAsync = True the script's current thread will
; move on to the next command(s) while speaking
SoundBeep, 2000, 1000 ;Speak and Beep at the same time
Wow, nice! Thank you for that info. I will take a look and see what I can do!

Check this code down below. I believe I can make something really cool..
It will go through the different types of voices you have.. I have 4, so I can
hear each one with this code right here..

Code: Select all

#SingleInstance Force
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
F1::

Global oVoice := ComObjCreate("SAPI.SpVoice"), voices := oVoice.GetVoices() ; Array of voices
For voice in voices {                                                       ; Loop through each voice
 ToolTip, % "Voice #" A_Index ": " voice.GetDescription()
 speak("Hey you over there with those EYES?", VOICENUMBER := A_Index, RATE := 2)   ; Speak in the designated voice
ToolTip
}
speak("Goodbye!", VOICENUMBER := 1)
peak("Goodbye!", VOICENUMBER := 2)
speak("Goodbye!", VOICENUMBER := 3, RATE := 2)
speak("Goodbye!", VOICENUMBER := 4)

speak(phrase, voiceNumber := 1, rate := 0, vol := 100) {                    ; Speak in a specific voice
 ; https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms723616(v=vs.85)
 oVoice.Volume := vol, oVoice.Rate := rate, oVoice.Voice:= voices.Item(voiceNumber - 1), oVoice.WaitUntilDone(True),
 oVoice.Speak(phrase)
}
Also, I found this code and its really sweet how it types out the words on the screen next to your mouse..

But I cant figure out how to add a different voice to this code here..

Code: Select all

#SingleInstance Force
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
F1::
global g_clipboard := "Hello, how are you today? I am great!"

SpVoice := ComObjCreate("SAPI.SpVoice")
SVSFlagsAsync := SPF_ASYNC := 1 << 0
SpVoice.Speak(g_clipboard, SVSFlagsAsync)

ComObjConnect(SpVoice, "Sp_")
Sp_Word(StreamNumber_Long, StreamPosition_Variant, CharacterPosition_Long, Length_Long, SpVoice_ComObj) {
	ToolTip % SubStr(g_clipboard, CharacterPosition_Long+1, Length_Long)
SetTimer, RemoveToolTip, -2000
return
}
RemoveToolTip:

	ToolTip

Return
;MsgBox

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Rohwedder » 10 Aug 2022, 02:47

Stop! You google some stuff and I should prepare it bite-size for you?
Have fun scripting, maybe we meet again in another thread.

User avatar
Justin-TestBot101a
Posts: 33
Joined: 04 Aug 2022, 20:00

Re: OSD Mouse Location and Cross Hair in same script issue...

Post by Justin-TestBot101a » 11 Aug 2022, 04:55

Rohwedder wrote:
10 Aug 2022, 02:47
Stop! You google some stuff and I should prepare it bite-size for you?
Have fun scripting, maybe we meet again in another thread.
Oh no.. I was not trying to do that.. Sorry if you thought.. I was just having fun.

I will not bother you. :thumbup:

P.S. I do love researching new ways to run code though and yes, I look up a lot
of stuff. But I am researching and learning fast.. I also found a new way of
finding the voice list and also double clicking will allow you to hear the voice
you clicked.. Pretty sweet little script.

Code: Select all

; ** Universal Header for my scripts **
#NoEnv
#InstallKeybdHook
#UseHook On
#SingleInstance Force ;only one instance of this script may run at a time!
#MaxHotkeysPerInterval 2000
#WinActivateForce ;https://autohotkey.com/docs/commands/_WinActivateForce.htm
DetectHiddenWindows, On
SetWorkingDir %A_ScriptDir%
SendMode Input
CoordMode, Mouse, Screen ; mouse coordinates relative to the screen

#MaxThreads, 100
#MaxThreadsPerHotkey 2
#Persistent
SetBatchLines, -1
CoordMode, Pixel, Screen
CoordMode, Tooltip, Screen
;CoordMode, Mouse, Window
;CoordMode, Pixel, Window
;CoordMode, Tooltip, Window
;CoordMode, Mouse, Client
;CoordMode, Pixel, Client
;CoordMode, Tooltip, Client
SetTitleMatchMode, 2
;SetTitleMatchMode, slow
SetKeyDelay, 100,100
SetMouseDelay 10
SetDefaultMouseSpeed, 0
;SendMode Event
;SendMode Play
;SendMode InputThenPlay
#InstallMouseHook

F12::

SayString := "Hello, this is how my voice sounds. Do you like it?"

v := ComObjCreate("SAPI.SpVoice")

; Create a ListView:
Gui, Add, ListView, r10 w400 gMyListView, Voice

; Gather a list of Voices and put them into the ListView:
For T In v.GetVoices
    LV_Add("", T.GetDescription)

LV_ModifyCol()  ; Auto-size each column to fit its contents.

; Display the window and return. 
Gui, Show
return

MyListView: ; This will run whenever the user double clicks a row.
v.Voice := v.GetVoices().Item(A_EventInfo-1) ; Item is Zero based
v.rate := 1 ; speak Rate
v.Speak(SayString) ; announce String
return

Post Reply

Return to “Gaming Help (v1)”