Beginners Tutorial: Notepad Gaming.

Helpful script writing tricks and HowTo's
earlbond84
Posts: 19
Joined: 16 Jul 2022, 09:26

Beginners Tutorial: Notepad Gaming.  Topic is solved

19 Jul 2022, 03:56

----------------------------------------------------------------------------------------------------------------------------
References (Requirements)
----------------------------------------------------------------------------------------------------------------------------

1. https://github.com/iseahound/ImagePut (v1.8+)
2. [removed by moderator]
3. AutoHotkey_1.1.34.03_setup+ (https://www.autohotkey.com/)
4. Window Activate/Focus is required.
5. Open Notepad with wintitle as "Untitled - Notepad".


----------------------------------------------------------------------------------------------------------------------------
Timer Skill Cooldown
----------------------------------------------------------------------------------------------------------------------------

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

global wintitleA := "Untitled - Notepad"


Buff(){
	if WinExist(wintitleA)
		WinActivate ; Use the window found by WinExist.
	
	ToolTip % "Buff"
}

#Persistent
SetTimer, Tick, 1000

Tick(){
	static count := 10
	ToolTip % count--
	
	if(count < 0){
		Buff()
		count := 10
	}
}

ESC:: ExitApp
Return
----------------------------------------------------------------------------------------------------------------------------
Windows Activate
----------------------------------------------------------------------------------------------------------------------------

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

wintitleA := "Untitled - Notepad"
wintitleB := "new 1 - Notepad++ [Administrator]"

OddOrEven(num){
	return ((Num & 1) != 0) ? "Odd" : "Even"
}

FocusA(title){
	if WinExist(title)
		WinActivate ; Use the window found by WinExist.
}
FocusB(title){
	if WinExist(title)
		WinActivate ; Use the window found by WinExist.
}

counter := 0
Loop{
	if(counter >= 10)
		ExitApp
	
	if(OddOrEven(counter) == "Odd")
		FocusA(wintitleA)
	
	if(OddOrEven(counter) == "Even")
		FocusB(wintitleB)
	
	counter++
	Sleep 1000
}
----------------------------------------------------------------------------------------------------------------------------
Windows Captured
----------------------------------------------------------------------------------------------------------------------------

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#include Lib\ImagePut.ahk
#singleinstance force

wintitle := Untitled - Notepad"

counter := 0
Loop{
	if(counter >= 11) 
		ExitApp
	
	if WinExist(wintitle){
		WinActivate ; Use the window found by WinExist.
	}
	
	winCaptured := ImagePutBuffer({window: wintitle})
	winCaptured.Show()
	winCaptured := ""
	
	counter++
	sleep 1000
}

----------------------------------------------------------------------------------------------------------------------------
Send Keys
----------------------------------------------------------------------------------------------------------------------------

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SetKeyDelay, 1000, 700
SetTitleMatchMode 2
wintitle := "Untitled - Notepad"

counter := 0
Loop{
	if(counter >= 10)
		ExitApp
	
	if WinExist(wintitle)
		WinActivate ; Use the window found by WinExist.
	
	Send {1 2}
	
	counter++
	Sleep 1000
}

Mod actions:
  • Moved topic from “Ask For Help”
  • Removed instruction to google site that OP has been spamming.
  • Added code tags to last piece of code
earlbond84
Posts: 19
Joined: 16 Jul 2022, 09:26

Re: BEGINNERS TUTORIAL: Notepad Gaming.

19 Jul 2022, 04:58

----------------------------------------------------------------------------------------------------------------------------
Window Screen Capture Crop Pixel Search
----------------------------------------------------------------------------------------------------------------------------

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#include ImagePut.ahk
#singleinstance force

wintitle := "Untitled - Notepad"

counter := 0
Loop{
	if(counter >= 11) 
		ExitApp
	
	if WinExist(wintitle){
		WinActivate ; Use the window found by WinExist.
	}
	
	winCaptured := ImagePutBuffer({window: wintitle, crop:[0,0,100,100], scale: 2.5})
	winCaptured.Show()
	if winCaptured.PixelSearch(0xFFFFFF, 3){
		ToolTip % "White Pixel Found"
	}
	winCaptured := ""
	
	counter++
	sleep 1000
}
User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: Beginners Tutorial: Notepad Gaming.

19 Jul 2022, 17:16

AHK beginners: You should be aware that there is a built-in loop counter variable called A_Index that simplifies your code relative to creating and maintaining your own counter variable. Its use would allow you to replace this structure used above:

Code: Select all

counter := 0
Loop{
	if(counter >= 11) 
		ExitApp
	
	counter++
}

...with this:

Code: Select all

Loop, 11 {
	
}
earlbond84
Posts: 19
Joined: 16 Jul 2022, 09:26

Re: Beginners Tutorial: Notepad Gaming.

19 Jul 2022, 18:32

Hi @boiler

Thanks for pointing this out.
jimfan
Posts: 3
Joined: 31 Jul 2022, 11:56

Re: Beginners Tutorial: Notepad Gaming.

31 Jul 2022, 12:19

Thanks for this Tutorial! It was very helpful for me.

Return to “Tutorials (v1)”

Who is online

Users browsing this forum: No registered users and 37 guests