Some Autohotkey scripts to make your computer better

  • Thread starter Deleted User
  • Start date
  • Views 4,107
  • Replies 6
  • Likes 3
D

Deleted User

Guest
OP
If you've never used autohotkey and need any help getting started I'll be happy to help.

Internet autoreconnect
If your internet randomly disconnects and isn't a major outage by your ISP, this will force it to reconnect within a few seconds. (I was just having this happen to me for months with 5G internet) Maybe goes without saying but replace the words your internet connection name goes here with your internet connection name.
#Persistent
#SingleInstance Force
SetTimer, CheckOnlineStatus,% 3*1000 ; for testing check the 'online' status every 5sec

CheckOnlineStatus:
(Ping() = "offline") ? Network("wlan") : Return ; if ping()ing results in being 'offline', reconnect the wifi connection, else let's wait another 15secs
Return
Ping(host="8.8.8.8") { ; pinging/requesting a response from the Google server
colPings := ComObjGet("winmgmts:").ExecQuery("Select * From Win32_PingStatus where Address = '" host "'")._NewEnum
While colPings[objStatus]
Return oS := (objStatus.StatusCode = "") || (objStatus.StatusCode != 0) ? "offline" : "online"
}
Network(type){
If (A_IPAddress1 = "127.0.0.1") ; detecting the 'local host' IP from your first network device, so let's ...
RunWait, % comspec " /c netsh " type " connect name=your internet connection name goes here",, hide ; connect to the router (and let's start thinking about how to provide the SSID and the pw if requested!)
Else
RunWait, % comspec " /c netsh " type " disconnect",,hide ; disconnect a current wifi connection
}

!x::Network("wlan")

Disable Caps Lock, Number Lock can't be disabled
Does anyone actually want Caps Lock on or Number keys off? I can't remember ever wanting either in my life.
; Set Lock keys permanently
SetNumlockState, AlwaysOn
SetCapsLockState, AlwaysOff
SetScrollLockState, AlwaysOff
return

Super Escape key to exit PC games
Since some PC games use Alt+F4 this combines Escape with Alt+F4 so you can escape most PC games with Esc. There are however still some stubborn ones that don't let you remap keys at all but this will work with most.
$ESC::Send !{F4}
return

Make a hotkey to launch any app
It's best to use Ctrl or alt obviously since you will usually want your keys to just type the letters you want it to type. Here's an example for ctrl or alt.
Ctrl+whatever key (example here is ctrl+y, can be numbers or F keys too or home or whatever)
HotKey, ^y, LaunchUpdate
return
LaunchUpdate:
Run, "full path to the application you want to run"
;...any code you need...
return
Alt+whatever key (example here is alt+7)
HotKey, !7, LaunchUpdate
return
LaunchUpdate:
Run, "full path to the application you want to run"
;...any code you need...
return

Delete key = Ctrl + Delete

This just makes it easier to delete something without having to hold ctrl with delete because I know with me most of the time items would end up in the recycling bin when I really want to get rid of them all together. You will still get confirmation do you want to delete item so no fear of using this unintentionally.
Send {LShift down};
Send {DEL};
Send {LShift up};

Restart Windows with a keyboard key (example home key)
I make two different scripts for this. The first one you can just click on the ahk and it will restart windows, I call it restart windows.exe (right click the ahk after you're done and you can compile it to an exe)
shutdown, 2

The second one will make it a keyboard key, I use ctrl+home.
HotKey, ^Home, LaunchUpdate
return
LaunchUpdate:
Run, "Restart Windows.exe"
;...any code you need...
return

Just do the same thing if you want to shut down just a slightly different script. Obviously don't use the same key as restart though.
run shutdown /s /f /t 0

These are just a few I use I use more than these. I have my laptop hooked up to my TV and I have a script to change screens from laptop to computer or vice versa or dual screen, and i have one to change audio to the computer or laptop, I have an app that can turn off my Xbox 360 controller and I turned it into ctrl+0 to do that. There's endless things you can do on autohotkey, even assign key to open gbatemp. Just about anything Microsoft was too lazy to add to Windows. You can add them to your start menu for easier access if it's a script you just want to click on and not use a key or for example the first script listed about internet reconnecting you would want to add that to startup so that it starts with windows and is always making sure your internet is connected. You could make loops to check a million other things too.

I started using this Saturn emulator called SSF and you had to mount the ISO using a virtual drive then launch the emulator and I never cared for having to do that every time I want to play a game, that's when I discovered autohotkey as it can mount the image and starts the emulator, and can unmount the ISO too if you want all with double click of a mouse or hotkey. It can be a lot of work getting these scripts to work sometimes, but when they work properly it makes your computer work smoother so you can be more lazy. I am lazy and want things to be easier even if I have to work hard to make it happen.
 
Last edited by ,
D

Deleted User

Guest
OP
10/10 thread, I started getting into AHK scripting, these are going to be very usefull, thank you :)

Cool, let me know if you run into any trouble or have any questions. I'm not an expert by any means though. There are people 100 times better than me at AHK.
 
  • Like
Reactions: Mama Looigi
D

Deleted User

Guest
OP
Oh and by the way be careful if you do use these scripts with shutdown or reset not to put them in startup. It will constantly restart or shutdown your computer right after starting it. I did it myself before accidentally.

Like mentioned in first post I make two scripts for shutdown and restart, one where you just click on it and it will restart or shutdown, the other is a hotkey that will run the first script. If you put the hotkey it is ok it will enable you to use that hotkey on startup, but if you put the actual shutdown/restart it will do it every launch and you will have to go into safe mode to remove the script from startup.
 
Last edited by ,

Vila_

Spanish code for Spanisher codecs
Member
Joined
Jun 21, 2018
Messages
552
Trophies
1
Location
my villa
Website
vilagamer999.github.io
XP
1,733
Country
Spain
Oh and by the way be careful if you do use these scripts with shutdown or reset not to put them in startup. It will constantly restart or shutdown your computer right after starting it. I did it myself before accidentally.

Like mentioned in first post I make two scripts for shutdown and restart, one where you just click on it and it will restart or shutdown, the other is a hotkey that will run the first script. If you put the hotkey it is ok it will enable you to use that hotkey on startup, but if you put the actual shutdown/restart it will do it every launch and you will have to go into safe mode to remove the script from startup.
Thankfully there is an easy way to fix this with (as you mentioned) safemode, thanks for the heads up tough :D
 
D

Deleted User

Guest
OP
Ok this would probably work better if you use a frontend to launch your emulators like Launchbox, but you could make it a script and run the game in the script too if you don't use any front ends. Yeah I mean you don't actually have to load the emulator up first and then load the game, the script can do both together for you. I only open the emulators to set them up, set controls etc... or maybe to test a game or something like that. But when I'm actually going to play a game I never open the emulator first and load the rom.

Automatically Load a save state when launching a rom from an emulator (example here is F3 = Load save state) Change according to your emulator.

#SingleInstance Force
Sleep 6000
Send {F3 Down}
Sleep 50
Send {F3 Up}
Return

Now if you wanted to run the emulator and rom in the same script, you'd have to figure out the commands for that emulator. I actually know quite a few of them so if you need help with one ask although not only one person has even responded in the thread period, but I'm hoping at least a few people are reading this and getting at least one thing out of it even if they don't reply if not oh well I guess I'm talking to myself.

Here's an example of running pcsx 2 emulator with a game and it loads the save state.

#SingleInstance Force
Run, D:\Downloads\pcsx2.exe "D:\Downloads\Dino Stalker\Dino Stalker.iso"
Sleep 6000
Send {F3 Down}
Sleep 50
Send {F3 Up}
Return
ExitApp

Notice the line
Run, "D:\Pawn\Downloads\pcsx2.exe" "D:\Downloads\Dino Stalker.iso"

This is my own path to where the emulator is and the game is, yours will no doubt be different. Something no one taught me I just had to learn was if you run the script from the same location as the .exe, you don't have to add a path for it. So if I make this script where pcsx.exe is located, it would instead be
Run, pcsx2.exe "D:\Downloads\Dino Stalker.iso"

But if I make it from anywhere else on my computer, I have to add the path. So if the iso and the emulator were in the same location I wouldn't need any paths added, otherwise I would need the paths.

Also notice this path
"D:\Downloads\Dino Stalker\Dino Stalker.iso"

Notice there's quotes around it. It's because Dino Stalker has a space in it. If the path had no spaces, you wouldn't need any quotes. If you add a space and don't add quotes, the script won't find your path. It's the same in command prompt. Spaces are bad, but quotes take care of them.
 
Last edited by ,

osirisjem

I miss the Wii remotes
Member
Joined
Jun 19, 2011
Messages
1,116
Trophies
1
XP
1,157
Country
Canada
type ddd to spit out the date

Code:
:*:ddd::  ; This hotstring replaces "ddd" with the current date and time via the commands below.
FormatTime, CurrentDateTime,, MMMM dd, yyyy  ; It will look like Jan 02, 2007
SendInput %CurrentDateTime%
return

type ttt to spit out the time

Code:
:*:ttt::  ; This hotstring replaces "ttt" with the current date and time via the commands below.
FormatTime, CurrentDateTime,, HH:mm  ; It will look like 21:09
SendInput %CurrentDateTime%
return

type \gbat \nin \col to spit out whatever text you want (in this case internet addresses)

Code:
:R:\gbat::https://gbatemp.net/threads/some-autohotkey-scripts-to-make-your-computer-better.586434/
:R:\nin::www.nintendo.com
:R:\col::https://colecovision.dk/
:R:\eof::You are an EOF loser.  No one cares about your weird posts, go back to 4chan.  Living in your mom's basement isn't normal.
 
  • Like
Reactions: Deleted User

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: Just beat it city