Company of Heroes

Autohotkey script (including chat)

Reply to this topic Start new topic
# 161RampageCrumpet Apr 20 2012, 05:54 AM
QUOTE
The game does it itself, script only changes into normal keys when pressing enter and returning into modified keys when pressing anything that leaves chat.


Mmm didnt work for me wacko.gif Doesnt shift+enter need to be sent to bring up All chat in 2v2s? Just that reading the script, i cant see it anywhere?

*edit* lol sorry beat me to it

Posts: 102

Game: Company of Heroes

+
# 162Dadinjo Apr 20 2012, 06:35 AM
There, this should work fix team and all chat.

Spoiler

SetTitleMatchMode, 2

IfWinNotExist Company Of Heroes
Run Company Of Heroes

#IfWinActive, Company Of Heroes

!CapsLock::
suspend , off
SoundBeep
return

^CapsLock::
{
suspend , on
SoundBeep
SoundBeep
hotkey, q, kbdhandler, Off
hotkey, w, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, x, kbdhandler, Off
entertoggle = 0
return
}

Escape:: ; Enables to escape chat and return to normal mode
{
if (entertoggle) {
entertoggle := !entertoggle
Send {Escape}
ChatMode(entertoggle)
}
else {
Escape::Escape
}
return
}

LButton:: ; Enables to escape chat and return to normal mode
{
if (entertoggle) {
entertoggle := !entertoggle
Send {LButton}
ChatMode(entertoggle)
}
else {
LButton::LButton
}
return
}

RButton:: ; Enables to escape chat and return to normal mode
{
if (entertoggle) {
entertoggle := !entertoggle
Send {RButton}
ChatMode(entertoggle)
}
else {
RButton::RButton
}
return
}

MButton:: ; Enables to escape chat and return to normal mode
{
if (entertoggle) {
entertoggle := !entertoggle
Send {MButton}
ChatMode(entertoggle)
}
else {
MButton::Backspace
}
return
}


kbdhandler:
If (A_ThisHotkey == "q") {
Send q
}
If (A_ThisHotkey == "w") {
Send w
}
If (A_ThisHotkey == "e") {
Send e
}
If (A_ThisHotkey == "a") {
Send a
}
If (A_ThisHotkey == "s") {
Send s
}
If (A_ThisHotkey == "d") {
Send d
}
If (A_ThisHotkey == "f") {
Send f
}
If (A_ThisHotkey == "x") {
Send x
}
If (A_ThisHotkey == "c") {
Send c
}
If (A_ThisHotkey == "+q") {
Send Q
}
If (A_ThisHotkey == "+w") {
Send W
}
If (A_ThisHotkey == "+e") {
Send E
}
If (A_ThisHotkey == "+a") {
Send A
}
If (A_ThisHotkey == "+s") {
Send S
}
If (A_ThisHotkey == "+d") {
Send D
}
If (A_ThisHotkey == "+f") {
Send F
}
If (A_ThisHotkey == "+x") {
Send X
}
If (A_ThisHotkey == "+c") {
Send C
}
return


w::up
s::down
a::left
d::right
q::a
e::D
f::numpad0
x::e
c::^c ; to have a shorcut for ping

; MButton::Backspace //already reconfigured

*Enter:: ;Enable chat (Team and all chat)
{
entertoggle := !entertoggle
if getKeyState("shift", "P") {
Send +{enter}
}
else {
Send {enter}
}
ChatMode(entertoggle)
}
return


*NumpadEnter:: ;Enable chat (Team and all chat)
{
entertoggle := !entertoggle
if getKeyState("shift", "P") {
Send +{enter}
}
else {
Send {enter}
}
ChatMode(entertoggle)
}
return


ChatMode(entertoggle){
if (entertoggle) {
hotkey, q, kbdhandler, On
hotkey, w, kbdhandler, On
hotkey, e, kbdhandler, On
hotkey, a, kbdhandler, On
hotkey, s, kbdhandler, On
hotkey, d, kbdhandler, On
hotkey, f, kbdhandler, On
hotkey, x, kbdhandler, On
hotkey, c, kbdhandler, On
hotkey, +q, kbdhandler, On
hotkey, +w, kbdhandler, On
hotkey, +e, kbdhandler, On
hotkey, +a, kbdhandler, On
hotkey, +s, kbdhandler, On
hotkey, +d, kbdhandler, On
hotkey, +f, kbdhandler, On
hotkey, +x, kbdhandler, On
hotkey, +c, kbdhandler, On
}
else{
hotkey, q, kbdhandler, Off
hotkey, w, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, x, kbdhandler, Off
hotkey, c, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +x, kbdhandler, Off
hotkey, +c, kbdhandler, Off
}
return entertoggle
}

Posts: 14

Game: Battle for Middle Earth

+
# 163RampageCrumpet Apr 20 2012, 06:51 AM
Good stuff, thankyou! biggrin.gif

Posts: 102

Game: Company of Heroes

+
# 164RampageCrumpet Apr 20 2012, 06:55 AM
Ok so I've made some improvements to my old script, with a BIG THANKS going out to Dadinjo for improving the chat function in his script, which I have added to mine.

So the script adds...
- Suspend/Resume moved to F7/F8 (So F1 - F6 is free for base selection hotkeys)
- Autoreinforce for up to 10 men across multiple squads - R
- Lay Mines (M)
- Lay Wire (N)
- Grenade (T, as no longer used for retreat command)
- Repair (Y)
- Unload/Exit Building (U) ALSO Snipe for British Recon Squad
+
- Shift now intergrated into the chat function to allow use of capitals (Improvement by Dadinjo)
- Troubles when chating ingame and pressing the keys (escape or mousebutton) resolved (Improvement by Dadinjo)
+
All the OP's original script hotkeys

Spoiler: Crumpets Autohotkey Script v1.1
CODE

SetTitleMatchMode, 2

#IfWinActive, Company Of Heroes
F8::
suspend , off
SoundBeep
return
F7::
{
suspend , on
SoundBeep, 1750, 800

hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
entertoggle = 0
return
}

y::e;Repair
u::d;Unload
t::n;Grenade
q::Numpad0;Tac Map
e::t;Retreat
w::up
a::left
s::down
d::right
f::a;Attack move
~::
{
SoundBeep
hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
entertoggle = 0
}

Escape::; Enables to escape chat and return to normal mode
{
if (entertoggle) {
entertoggle := !entertoggle
Send {Escape}
hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
entertoggle = 0
}
else {
Escape::Escape
}
return
}

LButton::; Enables to escape chat and return to normal mode
{
if (entertoggle) {
entertoggle := !entertoggle
Send {LButton}
hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
entertoggle = 0
}
else {
LButton::LButton
}
return
}

RButton::; Enables to escape chat and return to normal mode
{
if (entertoggle) {
entertoggle := !entertoggle
Send {RButton}
hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
entertoggle = 0
}
else {
RButton::RButton
}
return
}

kbdhandler:

If (A_ThisHotkey == "w") {
Send w
}
If (A_ThisHotkey == "a") {
Send a
}
If (A_ThisHotkey == "s") {
Send s
}
If (A_ThisHotkey == "d") {
Send d
}
If (A_ThisHotkey == "q") {
Send q
}
If (A_ThisHotkey == "e") {
Send e
}
If (A_ThisHotkey == "f") {
Send f
}
If (A_ThisHotkey == "r") {
Send r
}
If (A_ThisHotkey == "t") {
Send t
}
If (A_ThisHotkey == "m") {
Send m
}
If (A_ThisHotkey == "n") {
Send n
}
If (A_ThisHotkey == "u") {
Send u
}
If (A_ThisHotkey == "y") {
Send y
}
If (A_ThisHotkey == "+w") {
Send W
}
If (A_ThisHotkey == "+a") {
Send A
}
If (A_ThisHotkey == "+s") {
Send S
}
If (A_ThisHotkey == "+d") {
Send D
}
If (A_ThisHotkey == "+q") {
Send Q
}
If (A_ThisHotkey == "+e") {
Send E
}
If (A_ThisHotkey == "+f") {
Send F
}
If (A_ThisHotkey == "+r") {
Send R
}
If (A_ThisHotkey == "+t") {
Send T
}
If (A_ThisHotkey == "+m") {
Send M
}
If (A_ThisHotkey == "+n") {
Send N
}
If (A_ThisHotkey == "+u") {
Send U
}
If (A_ThisHotkey == "+y") {
Send Y
}

return

*ENTER UP::;Enable chat (Team and all chat)

entertoggle := !entertoggle

if getKeyState("shift", "P")
{
Send {shift down}{enter}{shift up}


hotkey, w, kbdhandler, On
hotkey, a, kbdhandler, On
hotkey, s, kbdhandler, On
hotkey, d, kbdhandler, On
hotkey, e, kbdhandler, On
hotkey, f, kbdhandler, On
hotkey, q, kbdhandler, On
hotkey, r, kbdhandler, On
hotkey, t, kbdhandler, On
hotkey, m, kbdhandler, On
hotkey, n, kbdhandler, On
hotkey, u, kbdhandler, On
hotkey, y, kbdhandler, On
hotkey, +w, kbdhandler, On
hotkey, +a, kbdhandler, On
hotkey, +s, kbdhandler, On
hotkey, +d, kbdhandler, On
hotkey, +e, kbdhandler, On
hotkey, +f, kbdhandler, On
hotkey, +q, kbdhandler, On
hotkey, +r, kbdhandler, On
hotkey, +t, kbdhandler, On
hotkey, +m, kbdhandler, On
hotkey, +n, kbdhandler, On
hotkey, +u, kbdhandler, On
hotkey, +y, kbdhandler, On
}

else {
Send {enter}

hotkey, w, kbdhandler, On
hotkey, a, kbdhandler, On
hotkey, s, kbdhandler, On
hotkey, d, kbdhandler, On
hotkey, e, kbdhandler, On
hotkey, f, kbdhandler, On
hotkey, q, kbdhandler, On
hotkey, r, kbdhandler, On
hotkey, t, kbdhandler, On
hotkey, m, kbdhandler, On
hotkey, n, kbdhandler, On
hotkey, u, kbdhandler, On
hotkey, y, kbdhandler, On
hotkey, +w, kbdhandler, On
hotkey, +a, kbdhandler, On
hotkey, +s, kbdhandler, On
hotkey, +d, kbdhandler, On
hotkey, +e, kbdhandler, On
hotkey, +f, kbdhandler, On
hotkey, +q, kbdhandler, On
hotkey, +r, kbdhandler, On
hotkey, +t, kbdhandler, On
hotkey, +m, kbdhandler, On
hotkey, +n, kbdhandler, On
hotkey, +u, kbdhandler, On
hotkey, +y, kbdhandler, On
}

if (entertoggle) {
hotkey, w, kbdhandler, On
hotkey, a, kbdhandler, On
hotkey, s, kbdhandler, On
hotkey, d, kbdhandler, On
hotkey, e, kbdhandler, On
hotkey, f, kbdhandler, On
hotkey, q, kbdhandler, On
hotkey, r, kbdhandler, On
hotkey, t, kbdhandler, on
hotkey, m, kbdhandler, On
hotkey, n, kbdhandler, On
hotkey, u, kbdhandler, On
hotkey, y, kbdhandler, On
hotkey, +w, kbdhandler, On
hotkey, +a, kbdhandler, On
hotkey, +s, kbdhandler, On
hotkey, +d, kbdhandler, On
hotkey, +e, kbdhandler, On
hotkey, +f, kbdhandler, On
hotkey, +q, kbdhandler, On
hotkey, +r, kbdhandler, On
hotkey, +t, kbdhandler, On
hotkey, +m, kbdhandler, On
hotkey, +n, kbdhandler, On
hotkey, +u, kbdhandler, On
hotkey, +y, kbdhandler, On
}

else {
hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
}

return

*r::;Autoreinforce
Loop 10
{
Send {r}
Send {Tab}
}
return

*m::;Mine
{
Send {b}
sleep 20
Send {m}
}
return

*n::;Wire
{
Send {b}
sleep 20
Send {w}
}
return

$MButton::;Enable Vehicle click-queued movement
Send {Rbutton}
Send {Shift Down};Delete this line if you don't want 1st click to be priorized.
Loop
{
if not GetKeyState("MButton", "P")
break
Send {Rbutton};
sleep 20
}
Send {Shift Up}
return


Everyone is free to use!

*Note* Mousebutton 3 will still cause issues when hit during chat, due to use for Move-Shift Vehicle function (Can't be bothered resolving at this time, as it will rarely happen)

Posts: 102

Game: Company of Heroes

+
# 165Dadinjo Apr 20 2012, 07:28 AM
RampageCrumpet, I think this would solve your issue with middlemouse button

Spoiler

$MButton::;Enable Vehicle click-queued movement
if (entertoggle) {
entertoggle := !entertoggle
Send {MButton}
hotkey, q, kbdhandler, Off
hotkey, w, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, x, kbdhandler, Off
hotkey, c, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +x, kbdhandler, Off
hotkey, +c, kbdhandler, Off
}
else
{
Send {Rbutton}
Send {Shift Down};Delete this line if you don't want 1st click to be priorized.
Loop
{
if not GetKeyState("MButton", "P")
break
Send {Rbutton};
sleep 20
}
Send {Shift Up}
}
return


This post has been edited by Dadinjo: Apr 20 2012, 09:31 AM

Posts: 14

Game: Battle for Middle Earth

+
# 166RampageCrumpet Apr 20 2012, 10:08 AM
Yeah it does, thats brilliant, thankyou once again Dadinjo!!! banana.gif

Posts: 102

Game: Company of Heroes

+
# 167RampageCrumpet Apr 20 2012, 10:24 AM
Ok so....

For the uninitiated in Autohotkey scripts, this is new version of my script without the mousebutton 3 problem! Again a BIG BIG BIG THANKS going out to Dadinjo for helping me improve the chat function once more.

So the script adds...
- Suspend/Resume moved to F7/F8 (So F1 - F6 is free for base selection hotkeys)
- Autoreinforce for up to 10 men across multiple squads - R
- Lay Mines (M)
- Lay Wire (N)
- Grenade (T, as no longer used for retreat command)
- Repair (Y)
- Unload/Exit Building (U) ALSO Snipe for British Recon Squad
+
- Shift now integrated into the chat function to allow use of capitals (Improvement by Dadinjo)
- Troubles when chating ingame and pressing the keys (escape or mousebutton) resolved (Improvement by Dadinjo)
- Trouble with chating ingame and pressing the middlemouse button (mousebutton 3) resolved (Improvement by Dadinjo)
+
All the OP's original script hotkeys

Spoiler: Crumpets Autohotkey Script v1.2
CODE

SetTitleMatchMode, 2

#IfWinActive, Company Of Heroes
F8::
suspend , off
SoundBeep
return
F7::
{
suspend , on
SoundBeep, 1750, 800

hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
entertoggle = 0
return
}

y::e;Repair
u::d;Unload
t::n;Grenade
q::Numpad0;Tac Map
e::t;Retreat
w::up
a::left
s::down
d::right
f::a;Attack move
~::
{
SoundBeep
hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
entertoggle = 0
}

Escape::; Enables to escape chat and return to normal mode
{
if (entertoggle) {
entertoggle := !entertoggle
Send {Escape}
hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
entertoggle = 0
}
else {
Escape::Escape
}
return
}

LButton::; Enables to escape chat and return to normal mode
{
if (entertoggle) {
entertoggle := !entertoggle
Send {LButton}
hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
entertoggle = 0
}
else {
LButton::LButton
}
return
}

RButton::; Enables to escape chat and return to normal mode
{
if (entertoggle) {
entertoggle := !entertoggle
Send {RButton}
hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
entertoggle = 0
}
else {
RButton::RButton
}
return
}

kbdhandler:

If (A_ThisHotkey == "w") {
Send w
}
If (A_ThisHotkey == "a") {
Send a
}
If (A_ThisHotkey == "s") {
Send s
}
If (A_ThisHotkey == "d") {
Send d
}
If (A_ThisHotkey == "q") {
Send q
}
If (A_ThisHotkey == "e") {
Send e
}
If (A_ThisHotkey == "f") {
Send f
}
If (A_ThisHotkey == "r") {
Send r
}
If (A_ThisHotkey == "t") {
Send t
}
If (A_ThisHotkey == "m") {
Send m
}
If (A_ThisHotkey == "n") {
Send n
}
If (A_ThisHotkey == "u") {
Send u
}
If (A_ThisHotkey == "y") {
Send y
}
If (A_ThisHotkey == "+w") {
Send W
}
If (A_ThisHotkey == "+a") {
Send A
}
If (A_ThisHotkey == "+s") {
Send S
}
If (A_ThisHotkey == "+d") {
Send D
}
If (A_ThisHotkey == "+q") {
Send Q
}
If (A_ThisHotkey == "+e") {
Send E
}
If (A_ThisHotkey == "+f") {
Send F
}
If (A_ThisHotkey == "+r") {
Send R
}
If (A_ThisHotkey == "+t") {
Send T
}
If (A_ThisHotkey == "+m") {
Send M
}
If (A_ThisHotkey == "+n") {
Send N
}
If (A_ThisHotkey == "+u") {
Send U
}
If (A_ThisHotkey == "+y") {
Send Y
}

return

*ENTER UP::;Enable chat (Team and all chat)

entertoggle := !entertoggle

if getKeyState("shift", "P")
{
Send {shift down}{enter}{shift up}


hotkey, w, kbdhandler, On
hotkey, a, kbdhandler, On
hotkey, s, kbdhandler, On
hotkey, d, kbdhandler, On
hotkey, e, kbdhandler, On
hotkey, f, kbdhandler, On
hotkey, q, kbdhandler, On
hotkey, r, kbdhandler, On
hotkey, t, kbdhandler, On
hotkey, m, kbdhandler, On
hotkey, n, kbdhandler, On
hotkey, u, kbdhandler, On
hotkey, y, kbdhandler, On
hotkey, +w, kbdhandler, On
hotkey, +a, kbdhandler, On
hotkey, +s, kbdhandler, On
hotkey, +d, kbdhandler, On
hotkey, +e, kbdhandler, On
hotkey, +f, kbdhandler, On
hotkey, +q, kbdhandler, On
hotkey, +r, kbdhandler, On
hotkey, +t, kbdhandler, On
hotkey, +m, kbdhandler, On
hotkey, +n, kbdhandler, On
hotkey, +u, kbdhandler, On
hotkey, +y, kbdhandler, On
}

else {
Send {enter}

hotkey, w, kbdhandler, On
hotkey, a, kbdhandler, On
hotkey, s, kbdhandler, On
hotkey, d, kbdhandler, On
hotkey, e, kbdhandler, On
hotkey, f, kbdhandler, On
hotkey, q, kbdhandler, On
hotkey, r, kbdhandler, On
hotkey, t, kbdhandler, On
hotkey, m, kbdhandler, On
hotkey, n, kbdhandler, On
hotkey, u, kbdhandler, On
hotkey, y, kbdhandler, On
hotkey, +w, kbdhandler, On
hotkey, +a, kbdhandler, On
hotkey, +s, kbdhandler, On
hotkey, +d, kbdhandler, On
hotkey, +e, kbdhandler, On
hotkey, +f, kbdhandler, On
hotkey, +q, kbdhandler, On
hotkey, +r, kbdhandler, On
hotkey, +t, kbdhandler, On
hotkey, +m, kbdhandler, On
hotkey, +n, kbdhandler, On
hotkey, +u, kbdhandler, On
hotkey, +y, kbdhandler, On
}

if (entertoggle) {
hotkey, w, kbdhandler, On
hotkey, a, kbdhandler, On
hotkey, s, kbdhandler, On
hotkey, d, kbdhandler, On
hotkey, e, kbdhandler, On
hotkey, f, kbdhandler, On
hotkey, q, kbdhandler, On
hotkey, r, kbdhandler, On
hotkey, t, kbdhandler, on
hotkey, m, kbdhandler, On
hotkey, n, kbdhandler, On
hotkey, u, kbdhandler, On
hotkey, y, kbdhandler, On
hotkey, +w, kbdhandler, On
hotkey, +a, kbdhandler, On
hotkey, +s, kbdhandler, On
hotkey, +d, kbdhandler, On
hotkey, +e, kbdhandler, On
hotkey, +f, kbdhandler, On
hotkey, +q, kbdhandler, On
hotkey, +r, kbdhandler, On
hotkey, +t, kbdhandler, On
hotkey, +m, kbdhandler, On
hotkey, +n, kbdhandler, On
hotkey, +u, kbdhandler, On
hotkey, +y, kbdhandler, On
}

else {
hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
}

return

*r::;Autoreinforce
Loop 10
{
Send {r}
Send {Tab}
}
return

*m::;Mine
{
Send {b}
sleep 20
Send {m}
}
return

*n::;Wire
{
Send {b}
sleep 20
Send {w}
}
return

$MButton::;Enable Vehicle click-queued movement
if (entertoggle) {
entertoggle := !entertoggle
Send {MButton}
hotkey, w, kbdhandler, Off
hotkey, a, kbdhandler, Off
hotkey, s, kbdhandler, Off
hotkey, d, kbdhandler, Off
hotkey, e, kbdhandler, Off
hotkey, f, kbdhandler, Off
hotkey, q, kbdhandler, Off
hotkey, r, kbdhandler, Off
hotkey, t, kbdhandler, Off
hotkey, m, kbdhandler, Off
hotkey, n, kbdhandler, Off
hotkey, u, kbdhandler, Off
hotkey, y, kbdhandler, Off
hotkey, +w, kbdhandler, Off
hotkey, +a, kbdhandler, Off
hotkey, +s, kbdhandler, Off
hotkey, +d, kbdhandler, Off
hotkey, +e, kbdhandler, Off
hotkey, +f, kbdhandler, Off
hotkey, +q, kbdhandler, Off
hotkey, +r, kbdhandler, Off
hotkey, +t, kbdhandler, Off
hotkey, +m, kbdhandler, Off
hotkey, +n, kbdhandler, Off
hotkey, +u, kbdhandler, Off
hotkey, +y, kbdhandler, Off
entertoggle = 0
}
else
{
Send {Rbutton}
Send {Shift Down};Delete this line if you don't want 1st click to be priorized.
Loop
{
if not GetKeyState("MButton", "P")
break
Send {Rbutton};
sleep 20
}
Send {Shift Up}
}
return


Everyone is free to use!

Posts: 102

Game: Company of Heroes

+
# 168Xalard Apr 20 2012, 16:26 PM
400 lines of code for a simple chat toggle?? Couldn't you use a function or a subroutine? This monstrosity is going to be huge pain for you if you'll ever want to add/remove hotkeys.

Posts: 1,015

Game: Company of Heroes

+
# 169RampageCrumpet Apr 20 2012, 22:14 PM
Yeah, i know. But hey, it works, so as long as i dont need to change it, we're all good!

But yeah, dear god, ive created a monster blink.gif

Posts: 102

Game: Company of Heroes

+
# 170kylito Apr 21 2012, 11:07 AM
QUOTE(RampageCrumpet @ Apr 20 2012, 22:14 PM) *

Yeah, i know. But hey, it works, so as long as i dont need to change it, we're all good!

But yeah, dear god, ive created a monster blink.gif


Good work rampageCrumpet. It's very hard to enable chat when the key mapping is different from the original.

It took me 2 days to develop chat code in order to enable 7-8 keys to use in chat.

Adding a subroutine?... you can try it, but remember the script is enabled so your WSAD keys are up,down,left,right. you are starting a subroutine when that keys are previously loaded.

Posts: 139

Game: Company of Heroes

+
# 171Dadinjo Apr 21 2012, 12:41 PM
I've made another script that uses slightly different approach.

It also solves some more bugs when using chat and pressing not only escape or mouse buttons but pressing those keys with modifiers up (for example pressing shift+mouse button when chatting)

Although script still has over 200 lines, code is not that redundant so you can change one thing in single spot.

Spoiler

SetTitleMatchMode, 2

#IfWinActive, Company Of Heroes



;TURNING THE SCRIPT ON AND OFF
!CapsLock::
suspend , off
SoundBeep
return

^CapsLock::
suspend , on
SoundBeep
SoundBeep
return



;RECONFIGURING KEYS
w::
+w::
{
if (entertoggle) {
WriteLetter("w")
}
else {
w::up
}
return
}

a::
+a::
{
if (entertoggle) {
WriteLetter("a")
}
else {
a::left
}
return
}

s::
+s::
{
if (entertoggle) {
WriteLetter("s")
}
else {
s::down
}
return
}

d::
+d::
{
if (entertoggle) {
WriteLetter("d")
}
else {
d::right
}
return
}

q::
{
if (entertoggle) {
WriteLetter("q")
}
else {
SendInput a
}
return
}

e::
{
if (entertoggle) {
WriteLetter("e")
}
else {
SendInput d
}
return
}

f::
{
if (entertoggle) {
WriteLetter("f")
}
else {
SendInput {numpad0}
}
return
}

x::
{
if (entertoggle) {
WriteLetter("x")
}
else {
SendInput e
}
return
}

c:: ;simplifying shortcut for capture here ping
{
if (entertoggle) {
WriteLetter("c")
}
else {
SendInput ^c
}
return
}


;MButton::Backspace ;reconfigured in a different place



WriteLetter(letter) {
if GetKeyState("Capslock", "T") {
if GetKeyState("Shift", "P") {
SendInput %letter%
}
else {
SendInput +%letter%
}
}
else if GetKeyState("Shift", "P") {
SendInput +%letter%
}
else {
SendInput %letter%
}
}


;TOGGLE OF THE CHAT
*Enter::
{
entertoggle := !entertoggle
if getKeyState("shift", "P") {
SendInput +{enter}
}
else {
SendInput {enter}
}
return
}

*NumpadEnter:: ;NEEDED BECAUSE IF YOU ENTER CHAT WITH ONE ENTER AND EXIT WITH ANOTHER IT SCREWS UP ENTERTOGGLE VALUE
{
entertoggle := !entertoggle
if getKeyState("shift", "P") {
SendInput +{enter}
}
else {
SendInput {enter}
}
return
}

Escape:: ;ENABLES TO ESCAPE CHAT AND RETURN TO NORMAL MODE
+Escape::
^Escape::
!Escape::
<^>!Escape::
{
if (entertoggle) {
entertoggle := !entertoggle
SendInput {Escape}
}
else {
Escape::Escape
}
return
}

LButton:: ;ENABLES TO ESCAPE CHAT AND RETURN TO NORMAL MODE
+LButton::
^LButton::
!LButton::
<^>!LButton::
^!LButton::
^+LButton::
+!LButton::
^+!LButton::
{
if (entertoggle) {
entertoggle := !entertoggle
SendInput {LButton}
}
else {
LButton::LButton
}
return
}

RButton:: ;ENABLES TO ESCAPE CHAT AND RETURN TO NORMAL MODE
+RButton::
^RButton::
!RButton::
<^>!RButton::
^!RButton::
^+RButton::
+!RButton::
^+!RButton::
{
if (entertoggle) {
entertoggle := !entertoggle
SendInput {RButton}
}
else {
RButton::RButton
}
return
}

*MButton:: ;ENABLES TO ESCAPE CHAT AND RETURN TO NORMAL MODE
{
if (entertoggle) {
entertoggle := !entertoggle
SendInput {MButton}
}
else {
SendInput {Backspace} ;CHANGES MIDDLE MOUSE BUTTON
}
return
}


One bug that still exist though, is when starting script from inside a ingame chat. But I dont see a way to fix that using autohotkeys.
It can still be solved easily by stoping and resuming script outside of chat.

This post has been edited by Dadinjo: Apr 21 2012, 13:11 PM

Posts: 14

Game: Battle for Middle Earth

+
# 172Xalard Apr 21 2012, 15:32 PM
I made a much simpler script. All you have to do is declare what hotkeys you are using and a function will do everything else.
Will turn hotkeys on properly when closing chat by mouse click or scroll. Obviously it still has to be manually disabled when chatting in lobby.

Note that I use tons of comments so it's much easier to read in editor which highlights syntax (such as Notepad++).

Colours:
Core parts of the script, don't edit those parts
Suspend/restart
Hotkey declaration part, including instructions
User hotkeys

Open spoiler to see code:
Spoiler

;Initialisation
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
Process, Priority, , High

;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
; ChatMode
;Author: Xalard
;Don't touch this part unless you know what you are doing.
; Parameters:
; list1 = mapped keys list
; list2 = hotkeys list
; mode:
; on - hotkeys DISABLED
; off - hotkeys ENABLED
; toggle

ChatOff: ;-needed to toggle chat off on mouse click
ChatMode(mapped, hotkeys, "off")

ChatMode(list1, list2, mode = "toggle")
{
static
; space removal
StringReplace, list1, list1, %A_Space%,,All
StringReplace, list1, list1, &,%A_Space%&%A_Space%,All ;fix for custom key combinations using &
StringReplace, list2, list2, %A_Space%,,All
StringReplace, list2, list2, &,%A_Space%&%A_Space%,All
; translate the "mode" argument to one to use with "Hotkey" function and set chat status
if mode = toggle
{
mode_hk = toggle
chat := !chat
}
else if mode = on
{
mode_hk = off
chat := 1
}
else if mode = off
{
mode_hk = on
chat := 0
}
else MsgBox, %mode% is not a valid parameter for ChatMode function!
; execute all necessary "Hotkey" commands
if list2 != ""
{
loop, parse, list2, `,
{
Hotkey, %A_LoopField%, %mode_hk%
}
}
if list1 != ""
{
loop, parse, list1, `,
{
Hotkey, *%A_LoopField%, %mode_hk%
Hotkey, *%A_LoopField% up, %mode_hk%
}
}
; Prevent mouse from fucking up the script
If chat = 0
{
Hotkey, ~*LButton, ChatOff, off
Hotkey, ~*RButton, ChatOff, off
Hotkey, ~*MButton, ChatOff, off
Hotkey, ~*WheelUp, ChatOff, off
Hotkey, ~*WheelDown, ChatOff, off
}
Else
{
Hotkey, ~*LButton, ChatOff, on
Hotkey, ~*RButton, ChatOff, on
Hotkey, ~*MButton, ChatOff, on
Hotkey, ~*WheelUp, ChatOff, on
Hotkey, ~*WheelDown, ChatOff, on
}
}
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Due to the way AHK handles global variables, hotkeys to toggle for the chat
; compatibilty have to be declared BEFORE the hotkeys themselves are set
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


; HOTKEYS
;Declare all hotkeys you want disabled when chatting

; CLOSING CHAT BY USING MOUSE BUTTONS
;This script will still work correctly if you use mouse click or scrollwheel to close the chat
;If you don't declare your mouse hotkeys below, the script might break if you use them when chatting


; Guidelines for listing keys in this section:
; separate keys using a comma ,
; modifiers such as in ~*Tab or !BS also have to be listed
; spaces are automatically removed
; if you have no keys to declare, leave the variable blank, eg. mapped := ""

; If you declare a hotkey that doesn't exist, the script will crash when you press Enter

;Declare all REMAPPED keys below:
; Remapped keys are keys that are coded like this:
; w::up
; Space::Numpad0
mapped := "w,a,s,d"

;Declare all other hotkeys below:
hotkeys := "+1,+2,+3,+4,+5,+6,MButton,+f,+LAlt"

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ALL hotkeys must be placed below this line
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

F9:: ;always on, in case #IfWinActive refuses to work
Suspend Off
SoundBeep
Reload
return

;======================================================
#IfWinActive, Company Of Heroes

;Suspend
F11::
SoundBeep, 1750, 800
Suspend On
return


;ChatMode
~*NumpadEnter::
~*Enter::ChatMode(mapped, hotkeys, "toggle")
~*Esc::ChatMode(mapped, hotkeys, "off")
;/Chatmode


;Arrow keys
w::up
a::left
s::down
d::right
;HALT!
CapsLock::l
;Next/prev unit
Xbutton1::Home
Xbutton2::End
;Base buildings
+1::send {F1}
+2::send {F2}
+3::send {F3}
+4::send {F4}
+5::send {F5}
+6::send {F6}
;Destroy building
+f::send {Del}{Del}

;Camera setup
Cam: ;Basic camera reset function, remember to use "BlockInput MouseMoveOff" after it
{
BlockInput MouseMove
send {BS}
send {BS}
MouseClick,WheelDown,,,30,0,D,R
}
return

+LAlt:: ;Basic reset
{
Gosub, Cam
BlockInput MouseMoveOff
}
Send {LAlt Up}
return

;Vehicle click-queue script
MButton::
Send {Rbutton}
Send {Shift Down} ;Delete this line if you don't want 1st click to be priorized.
Loop
{
if not GetKeyState("MButton", "P")
break
Send {Rbutton}
sleep 20 ;sets delay between clicks
}
Send {Shift Up}
return

return


This post has been edited by Xalard: Apr 21 2012, 15:47 PM

Posts: 1,015

Game: Company of Heroes

+
# 173Dadinjo Apr 21 2012, 18:15 PM
Yep, a simplier solution definitly. Easier to remap for sure.

Now, couldn't you have done this couple of days ago and saved us the trouble of figuring how the autoscripts works smile.gif

Posts: 14

Game: Battle for Middle Earth

+
# 174Xalard Apr 21 2012, 18:37 PM
Well, I hoped you guys would figure something out and save me work smile.gif But seeing that you didn't I had to stop being lazy and finally make one myself.

Posts: 1,015

Game: Company of Heroes

+
# 175RampageCrumpet Apr 22 2012, 05:50 AM
QUOTE(Dadinjo @ Apr 21 2012, 18:15 PM) *

Yep, a simplier solution definitly. Easier to remap for sure.

Now, couldn't you have done this couple of days ago and saved us the trouble of figuring how the autoscripts works smile.gif


Lol, agreed.

But, whoa nice! I defer to your expertise Xalard, you is pro!

Well played sir, well played thumb.gif

Posts: 102

Game: Company of Heroes

+
# 176kylito Apr 24 2012, 22:14 PM
QUOTE(RampageCrumpet @ Apr 22 2012, 05:50 AM) *

Lol, agreed.

But, whoa nice! I defer to your expertise Xalard, you is pro!

Well played sir, well played thumb.gif


Soon we will have a final solution. Adaptable to all players. All your configurations will be allowed. And it will be for free.

Posts: 139

Game: Company of Heroes

+
# 177RampageCrumpet Apr 29 2012, 07:25 AM
CRUMPETS AUTOHOTKEY SCRIPT v2.0 - (Script by Xalard, Edited by RampageCrumpet)

Ok Ladies and Gentlemen, I've finally had some time to play with Xalards script, and have brought over all the features of my old scripts into the new! A massive thankyou goes out to Xalard for writing this script, and allowing us all to use it!

Script features include...
F11/F9 - Suspend/Resume
w,a,s,d - Controls Camera Movement
CapsLock - Halt
q - Tactical Map
e - Retreat
t - Grenade
y - Sticky Bomb
u - Unload
f - Attack Move
h - Hold Fire
n - Sandbags
m - Mine
k - Tank Traps
l - Wire
r - AutoReinforce (Reinforce multiple selected squads)
Shift+Alt - Quick Camera Reset
MiddleMouse - Vehicle Click-queue Script
(See Video: http://www.youtube.com/watch?v=Hv-n_IbKalI)
+
Improved Chat - Hotkeys disable during chat, so all you E's don't turn into T's! Plus no more bugs when hitting Esc or MouseButtons either!

CONFUSED?
For those who have never used a script before a small Tutorial is included below...
Spoiler: Beginners Tutorial To Autohotkey Scripts
Hi there! smile.gif
Autohotkey is a freely available program that allows its users to configure any key on your keyboard to execute certain commands. In this case, we are using Autohotkey to reconfigure keys for Company of Heroes. For example, changing the w,a,s,d keys to move the camera. This can be one of the ways to improve your micromanagement skills, so you can play the game more efficiently and hopefully win more often!

Autohotkey runs its own special code, called a script, which tells the program what to do, such as my one below. If you would like to use a script to modify your Company of Heroes Hotkeys, you must...
1. Download and Install Autohotkey. You can get it from here at: http://www.autohotkey.com/download/
2. Copy and Paste the entire script into Notepad on your computer.
3. Go to File > Save As...
4. Select where you would like the script to be saved.
5. In the File Name box, name your script something appropriate, followed by .ahk (E.g. MyScript.ahk)
6. Click Save! When you want to play Company of Heroes, just double click on the Script icon before opening the game. Have fun!

*Note* If you are using a Company of Heroes mod, make sure you right click the script and select Run as Administrator otherwise your script will not work in-game.

THE SCRIPT
Copy & Paste...
Spoiler: Crumpets Autohotkey Script v2.0

;Initialisation
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
Process, Priority, , High

;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
; ChatMode
;Author: Xalard
;Don't touch this part unless you know what you are doing.
; Parameters:
; list1 = mapped keys list
; list2 = hotkeys list
; mode:
; on - hotkeys DISABLED
; off - hotkeys ENABLED
; toggle

ChatOff: ;-needed to toggle chat off on mouse click
ChatMode(mapped, hotkeys, "off")

ChatMode(list1, list2, mode = "toggle")
{
static
; space removal
StringReplace, list1, list1, %A_Space%,,All
StringReplace, list1, list1, &,%A_Space%&%A_Space%,All;fix for custom key combinations using &
StringReplace, list2, list2, %A_Space%,,All
StringReplace, list2, list2, &,%A_Space%&%A_Space%,All
; translate the "mode" argument to one to use with "Hotkey" function and set chat status
if mode = toggle
{
mode_hk = toggle
chat := !chat
}
else if mode = on
{
mode_hk = off
chat := 1
}
else if mode = off
{
mode_hk = on
chat := 0
}
else MsgBox, %mode% is not a valid parameter for ChatMode function!
; execute all necessary "Hotkey" commands
if list2 != ""
{
loop, parse, list2, `,
{
Hotkey, %A_LoopField%, %mode_hk%
}
}
if list1 != ""
{
loop, parse, list1, `,
{
Hotkey, *%A_LoopField%, %mode_hk%
Hotkey, *%A_LoopField% up, %mode_hk%
}
}
; Prevent mouse from fucking up the script
If chat = 0
{
Hotkey, ~*LButton, ChatOff, off
Hotkey, ~*RButton, ChatOff, off
Hotkey, ~*MButton, ChatOff, off
Hotkey, ~*WheelUp, ChatOff, off
Hotkey, ~*WheelDown, ChatOff, off
}
Else
{
Hotkey, ~*LButton, ChatOff, on
Hotkey, ~*RButton, ChatOff, on
Hotkey, ~*MButton, ChatOff, on
Hotkey, ~*WheelUp, ChatOff, on
Hotkey, ~*WheelDown, ChatOff, on
}
}
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Due to the way AHK handles global variables, hotkeys to toggle for the chat
; compatibilty have to be declared BEFORE the hotkeys themselves are set
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


; HOTKEYS
;Declare all hotkeys you want disabled when chatting

; CLOSING CHAT BY USING MOUSE BUTTONS
;This script will still work correctly if you use mouse click or scrollwheel to close the chat
;If you don't declare your mouse hotkeys below, the script might break if you use them when chatting


; Guidelines for listing keys in this section:
; separate keys using a comma ,
; modifiers such as in ~*Tab or !BS also have to be listed
; spaces are automatically removed
; if you have no keys to declare, leave the variable blank, eg. mapped := ""

; If you declare a hotkey that doesn't exist, the script will crash when you press Enter

;Declare all REMAPPED keys below:
; Remapped keys are keys that are coded like this:
; w::up
; Space::Numpad0
mapped := "w,a,s,d,q,e,t,y,u,f,CapsLock,h"

;Declare all other hotkeys below:
hotkeys := "MButton,r,n,k,l,m,+LAlt"

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ALL hotkeys must be placed below this line
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

F9:: ;always on, in case #IfWinActive refuses to work
Suspend Off
SoundBeep
Reload
return

;======================================================
#IfWinActive, Company Of Heroes

;Suspend
F11::
SoundBeep, 1750, 800
Suspend On
return

;------------------------------------------------------

;ChatMode
~*NumpadEnter::
~*Enter::ChatMode(mapped, hotkeys, "toggle")
~*Esc::ChatMode(mapped, hotkeys, "off")
;/Chatmode

;------------------------------------------------------

;Arrow keys
w::up
a::left
s::down
d::right

;Tac Map
q::Numpad0

;Retreat
e::t

;Grenade
t::n

;Sticky Bomb
y:: s

;Unload
u:: d

;Attack move
f::a

;Hold Fire
h:: d

;HALT!
CapsLock::h

;------------------------------------------------------

;Quick Lay - Sand Bags
n::
{
Send {b}
sleep 20
Send {s}
}
return

;Quick Lay - Tank Traps
k::
{
Send {b}
sleep 20
Send {t}
}
return

;Quick Lay - Wire
l::
{
Send {b}
sleep 20
Send {w}
}
return

;Quick Lay - Mine
m::
{
Send {b}
sleep 20
Send {m}
}
return

;Basic/Quick Camera Reset Function Setup
Cam: ;Basic camera reset function, remember to use "BlockInput MouseMoveOff" after it
{
BlockInput MouseMove
send {BS}
send {BS}
MouseClick,WheelDown,,,30,0,D,R
}
return

;Basic/Quick Camera Reset
+LAlt::
{
Gosub, Cam
BlockInput MouseMoveOff
}
Send {LAlt Up}
return

;Auto-reinforce
r::
Loop 10
{
Send {r}
Send {Tab}
}
return

;Vehicle click-queue script
MButton::
Send {Rbutton}
Send {Shift Down} ;Delete this line if you don't want 1st click to be priorized.
Loop
{
if not GetKeyState("MButton", "P")
break
Send {Rbutton}
sleep 20 ;sets delay between clicks
}
Send {Shift Up}
return

;------------------------------------------------------

return

WANT YOUR OWN UNIQUE HOTKEYS?
For those wanting to Modify the above Script or Create their Own Unique Autohotkey Script, but are not sure how, follow the Guide below...
Spoiler: Advanced Tutorial: Modifying Your Script

If you right click on your script, you will see the option edit script in the context menu. Click on the edit script option and it will bring up your scripts code in Notepad. It is from here we can modify the code so Autohotkey does what we want. Don't forget to save your script before exiting, then reload it again to test.

*Note* Keep in mind that every line that begins with a semicolon ; is just for our benefit as a note. These are not executed by Autohotkey.

Now if we Look Again at the Script from Above...
Spoiler

;Initialisation
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
Process, Priority, , High

;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
; ChatMode
;Author: Xalard
;Don't touch this part unless you know what you are doing.
; Parameters:
; list1 = mapped keys list
; list2 = hotkeys list
; mode:
; on - hotkeys DISABLED
; off - hotkeys ENABLED
; toggle

ChatOff: ;-needed to toggle chat off on mouse click
ChatMode(mapped, hotkeys, "off")

ChatMode(list1, list2, mode = "toggle")
{
static
; space removal
StringReplace, list1, list1, %A_Space%,,All
StringReplace, list1, list1, &,%A_Space%&%A_Space%,All ;fix for custom key combinations using &
StringReplace, list2, list2, %A_Space%,,All
StringReplace, list2, list2, &,%A_Space%&%A_Space%,All
; translate the "mode" argument to one to use with "Hotkey" function and set chat status
if mode = toggle
{
mode_hk = toggle
chat := !chat
}
else if mode = on
{
mode_hk = off
chat := 1
}
else if mode = off
{
mode_hk = on
chat := 0
}
else MsgBox, %mode% is not a valid parameter for ChatMode function!
; execute all necessary "Hotkey" commands
if list2 != ""
{
loop, parse, list2, `,
{
Hotkey, %A_LoopField%, %mode_hk%
}
}
if list1 != ""
{
loop, parse, list1, `,
{
Hotkey, *%A_LoopField%, %mode_hk%
Hotkey, *%A_LoopField% up, %mode_hk%
}
}
; Prevent mouse from fucking up the script
If chat = 0
{
Hotkey, ~*LButton, ChatOff, off
Hotkey, ~*RButton, ChatOff, off
Hotkey, ~*MButton, ChatOff, off
Hotkey, ~*WheelUp, ChatOff, off
Hotkey, ~*WheelDown, ChatOff, off
}
Else
{
Hotkey, ~*LButton, ChatOff, on
Hotkey, ~*RButton, ChatOff, on
Hotkey, ~*MButton, ChatOff, on
Hotkey, ~*WheelUp, ChatOff, on
Hotkey, ~*WheelDown, ChatOff, on
}
}
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Due to the way AHK handles global variables, hotkeys to toggle for the chat
; compatibilty have to be declared BEFORE the hotkeys themselves are set
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



; HOTKEYS
;Declare all hotkeys you want disabled when chatting

; CLOSING CHAT BY USING MOUSE BUTTONS
;This script will still work correctly if you use mouse click or scrollwheel to close the chat
;If you don't declare your mouse hotkeys below, the script might break if you use them when chatting


; Guidelines for listing keys in this section:
; separate keys using a comma ,
; modifiers such as in ~*Tab or !BS also have to be listed
; spaces are automatically removed
; if you have no keys to declare, leave the variable blank, eg. mapped := ""

; If you declare a hotkey that doesn't exist, the script will crash when you press Enter

;Declare all REMAPPED keys below:
; Remapped keys are keys that are coded like this:
; w::up
; Space::Numpad0

mapped := "w,a,s,d,q,e,t,y,u,f,CapsLock,h"

;Declare all other hotkeys below:
hotkeys := "MButton,r,n,k,l,m,+LAlt"

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ALL hotkeys must be placed below this line
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


F9:: ;always on, in case #IfWinActive refuses to work
Suspend Off
SoundBeep
Reload
return

;======================================================
#IfWinActive, Company Of Heroes

;Suspend
F11::
SoundBeep, 1750, 800
Suspend On
return


;------------------------------------------------------

;ChatMode
~*NumpadEnter::
~*Enter::ChatMode(mapped, hotkeys, "toggle")
~*Esc::ChatMode(mapped, hotkeys, "off")
;/Chatmode

;------------------------------------------------------


;Arrow keys
w::up
a::left
s::down
d::right

;Tac Map
q::Numpad0

;Retreat
e::t

;Grenade
t::n

;Sticky Bomb
y:: s

;Unload
u:: d

;Attack move
f::a

;Hold Fire
h:: d

;HALT!
CapsLock::h


;------------------------------------------------------

;Quick Lay - Sand Bags
n::
{
Send {b}
sleep 20
Send {s}
}
return

;Quick Lay - Tank Traps
k::
{
Send {b}
sleep 20
Send {t}
}
return

;Quick Lay - Wire
l::
{
Send {b}
sleep 20
Send {w}
}
return

;Quick Lay - Mine
m::
{
Send {b}
sleep 20
Send {m}
}
return

;Basic/Quick Camera Reset Function Setup
Cam: ;Basic camera reset function, remember to use "BlockInput MouseMoveOff" after it
{
BlockInput MouseMove
send {BS}
send {BS}
MouseClick,WheelDown,,,30,0,D,R
}
return

;Basic/Quick Camera Reset
+LAlt::
{
Gosub, Cam
BlockInput MouseMoveOff
}
Send {LAlt Up}
return

;Auto-reinforce
r::
Loop 10
{
Send {r}
Send {Tab}
}
return

;Vehicle click-queue script
MButton::
Send {Rbutton}
Send {Shift Down} ;Delete this line if you don't want 1st click to be priorized.
Loop
{
if not GetKeyState("MButton", "P")
break
Send {Rbutton}
sleep 20 ;sets delay between clicks
}
Send {Shift Up}
return


;------------------------------------------------------

return

COLOURS

Red, Blue & Purple:
This is the core of the script. DO NOT TOUCH!

Instructions for hotkey declaration. If you understand them, great! If not, dont worry you can just ignore them. DONT NEED TO TOUCH THIS.

This is the Suspend/Resume function for turning the script on and off when in the lobby. As you can see, F11 is set to suspend, and F9 to suspend off (resume). Unless it is a necessity, you DONT NEED TO TOUCH THIS.

Green & Orange:
The orange section of the script is for Remapped Keys, which look like this -

w::up

Remapping Keys is one of the simplest things you do with Autohotkey. Just pick the hotkey you would like to use (e.g. w), followed by a double colon :: , followed by the key you want it to act for/as (up). So your code is w::up. Now when you press w, the camera moves up. Easy! But before we can get this to work, we must declare our hotkey (w) and place it in the long orange section of the script. See below for more info!



The green section of the script is for all other hotkeys, such as the Lay Mine function, which looks like this -

m::
{
Send {b}
sleep 20
Send {m}
}
return

Hotkeys like this which perform a function are a little more complicated, but hopefully we can guide you through! Using the above as an example, firstly you pick the hotkey you want to use (e.g. m), followed by a double colon :: .
In this function, we want it to select the build menu of our engineer/pioneer/sapper team by sending the b key, followed by selecting mines by sending the m key.
So, begining the commands with a curly braket { , we write (send {b}), followed on the next line by (sleep 20). This command causes the script to pause for a fraction of a second, preventing a lag bug occuring. Again, this is followed on the next line by (send {m}). Close the curly braket } , and on the very last line write (return). So the code looks like
m::
{
Send {b}
sleep 20
Send {m}
}
return

Now when a engineer/pioneer/sapper team is selected, you just press the m key, and the build mine option is selected for you! Easy! But before we can get this to work, we must declare our hotkey (m) and place it in the long green section of the script. See below for more info!


DECLARING HOTKEYS
Before we can go any further we must declare the hotkeys we intend to use. This is done in the single orange and green lines as seen below...

Firstly, all your hotkeys you want to use must be "declared" in this section here...
QUOTE

;Declare all REMAPPED keys below:
; Remapped keys are keys that are coded like this:
; w::up
; Space::Numpad0

mapped := "w,a,s,d,q,e,t,y,u,f,CapsLock,h"

;Declare all other hotkeys below:
hotkeys := "MButton,r,n,k,l,m,+LAlt"

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ALL hotkeys must be placed below this line
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


The orange line is where your remapped hotkeys declarations go. So from our example above our declaration would be

mapped := "w"

The green line is where all your other hotkeys declarations go. So from our Lay Mine function in the example above, our declaration would be

hotkeys := "m"

If you have more than one key to declare, just seperate them with a comma , as seen above. However make sure they are enclosed in the quotation marks " .
E.g.
hotkeys := "m,n,l,k"

*Note* Hotkeys MUST be declared for the script to work correctly.

PLACING YOUR CODE INTO THE SCRIPT
This will only take a moment. So you now have your code and have declared your hotkeys. All that remains is to Cut & Paste your code into the correct section.
Remember, place your remapped keys in the orange section, and all others in the green section, as seen below.

QUOTE
~*Enter::ChatMode(mapped, hotkeys, "toggle")
~*Esc::ChatMode(mapped, hotkeys, "off")
;/Chatmode

;------------------------------------------------------


;Arrow keys
w::up
a::left
s::down
d::right

;Tac Map
q::Numpad0

;Retreat
e::t

;Grenade
t::n

;Sticky Bomb
y:: s

;Unload
u:: d

;Attack move
f::a

;Hold Fire
h:: d

;HALT!
CapsLock::h


;------------------------------------------------------

;Quick Lay - Sand Bags
n::
{
Send {b}
sleep 20
Send {s}
}
return

;Quick Lay - Tank Traps
k::
{
Send {b}
sleep 20
Send {t}
}
return

;Quick Lay - Wire
l::
{
Send {b}
sleep 20
Send {w}
}
return

;Quick Lay - Mine
m::
{
Send {b}
sleep 20
Send {m}
}
return

;Basic/Quick Camera Reset Function Setup
Cam: ;Basic camera reset function, remember to use "BlockInput MouseMoveOff" after it
{
BlockInput MouseMove
send {BS}
send {BS}
MouseClick,WheelDown,,,30,0,D,R
}
return

;Basic/Quick Camera Reset
+LAlt::
{
Gosub, Cam
BlockInput MouseMoveOff
}
Send {LAlt Up}
return

;Auto-reinforce
r::
Loop 10
{
Send {r}
Send {Tab}
}
return

;Vehicle click-queue script
MButton::
Send {Rbutton}
Send {Shift Down} ;Delete this line if you don't want 1st click to be priorized.
Loop
{
if not GetKeyState("MButton", "P")
break
Send {Rbutton}
sleep 20 ;sets delay between clicks
}
Send {Shift Up}
return

;------------------------------------------------------

return


If you wish to organise and name your sections of code, remember to use a semicolon ; at the start of the line. E.g. As seen above...

;Vehicle click-queue script

Again, this is a note just for you, and is completely ignored by the program.

WORKING EXAMPLE
Yesyamaha brought up that he just wanted to remove one section of the script, the part with the Auto-reinforce function. This is how it would be done...

Remove ,r from the declaration in this section
QUOTE
; spaces are automatically removed
; if you have no keys to declare, leave the variable blank, eg. mapped := ""

; If you declare a hotkey that doesn't exist, the script will crash when you press Enter

;Declare all REMAPPED keys below:
; Remapped keys are keys that are coded like this:
; w::up
; Space::Numpad0
mapped := "w,a,s,d,q,e,t,y,u,f,CapsLock,h"

;Declare all other hotkeys below:
hotkeys := "MButton,r,n,k,l,m,+LAlt"

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ALL hotkeys must be placed below this line
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

F9:: ;always on, in case #IfWinActive refuses to work
Suspend Off


And remove ;Auto-reinforce...etc from this section of the script
QUOTE
BlockInput MouseMove
send {BS}
send {BS}
MouseClick,WheelDown,,,30,0,D,R
}
return

;Basic/Quick Camera Reset
+LAlt::
{
Gosub, Cam
BlockInput MouseMoveOff
}
Send {LAlt Up}
return

;Auto-reinforce
r::
Loop 10
{
Send {r}
Send {Tab}
}
return


;Vehicle click-queue script
MButton::
Send {Rbutton}
Send {Shift Down} ;Delete this line if you don't want 1st click to be priorized.
Loop
{
if not GetKeyState("MButton", "P")
break
Send {Rbutton}


Full script, with lines to delete highlighted in Red
Spoiler

;Initialisation
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
Process, Priority, , High

;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
; ChatMode
;Author: Xalard
;Don't touch this part unless you know what you are doing.
; Parameters:
; list1 = mapped keys list
; list2 = hotkeys list
; mode:
; on - hotkeys DISABLED
; off - hotkeys ENABLED
; toggle

ChatOff: ;-needed to toggle chat off on mouse click
ChatMode(mapped, hotkeys, "off")

ChatMode(list1, list2, mode = "toggle")
{
static
; space removal
StringReplace, list1, list1, %A_Space%,,All
StringReplace, list1, list1, &,%A_Space%&%A_Space%,All ;fix for custom key combinations using &
StringReplace, list2, list2, %A_Space%,,All
StringReplace, list2, list2, &,%A_Space%&%A_Space%,All
; translate the "mode" argument to one to use with "Hotkey" function and set chat status
if mode = toggle
{
mode_hk = toggle
chat := !chat
}
else if mode = on
{
mode_hk = off
chat := 1
}
else if mode = off
{
mode_hk = on
chat := 0
}
else MsgBox, %mode% is not a valid parameter for ChatMode function!
; execute all necessary "Hotkey" commands
if list2 != ""
{
loop, parse, list2, `,
{
Hotkey, %A_LoopField%, %mode_hk%
}
}
if list1 != ""
{
loop, parse, list1, `,
{
Hotkey, *%A_LoopField%, %mode_hk%
Hotkey, *%A_LoopField% up, %mode_hk%
}
}
; Prevent mouse from fucking up the script
If chat = 0
{
Hotkey, ~*LButton, ChatOff, off
Hotkey, ~*RButton, ChatOff, off
Hotkey, ~*MButton, ChatOff, off
Hotkey, ~*WheelUp, ChatOff, off
Hotkey, ~*WheelDown, ChatOff, off
}
Else
{
Hotkey, ~*LButton, ChatOff, on
Hotkey, ~*RButton, ChatOff, on
Hotkey, ~*MButton, ChatOff, on
Hotkey, ~*WheelUp, ChatOff, on
Hotkey, ~*WheelDown, ChatOff, on
}
}
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Due to the way AHK handles global variables, hotkeys to toggle for the chat
; compatibilty have to be declared BEFORE the hotkeys themselves are set
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


; HOTKEYS
;Declare all hotkeys you want disabled when chatting

; CLOSING CHAT BY USING MOUSE BUTTONS
;This script will still work correctly if you use mouse click or scrollwheel to close the chat
;If you don't declare your mouse hotkeys below, the script might break if you use them when chatting


; Guidelines for listing keys in this section:
; separate keys using a comma ,
; modifiers such as in ~*Tab or !BS also have to be listed
; spaces are automatically removed
; if you have no keys to declare, leave the variable blank, eg. mapped := ""

; If you declare a hotkey that doesn't exist, the script will crash when you press Enter

;Declare all REMAPPED keys below:
; Remapped keys are keys that are coded like this:
; w::up
; Space::Numpad0
mapped := "w,a,s,d,q,e,t,y,u,f,CapsLock,h"

;Declare all other hotkeys below:
hotkeys := "MButton,r,n,k,l,m,+LAlt"

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ALL hotkeys must be placed below this line
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

F9:: ;always on, in case #IfWinActive refuses to work
Suspend Off
SoundBeep
Reload
return

;======================================================
#IfWinActive, Company Of Heroes

;Suspend
F11::
SoundBeep, 1750, 800
Suspend On
return

;------------------------------------------------------

;ChatMode
~*NumpadEnter::
~*Enter::ChatMode(mapped, hotkeys, "toggle")
~*Esc::ChatMode(mapped, hotkeys, "off")
;/Chatmode

;------------------------------------------------------

;Arrow keys
w::up
a::left
s::down
d::right

;Tac Map
q::Numpad0

;Retreat
e::t

;Grenade
t::n

;Sticky Bomb
y:: s

;Unload
u:: d

;Attack move
f::a

;Hold Fire
h:: d

;HALT!
CapsLock::h

;------------------------------------------------------

;Quick Lay - Sand Bags
n::
{
Send {b}
sleep 20
Send {s}
}
return

;Quick Lay - Tank Traps
k::
{
Send {b}
sleep 20
Send {t}
}
return

;Quick Lay - Wire
l::
{
Send {b}
sleep 20
Send {w}
}
return

;Quick Lay - Mine
m::
{
Send {b}
sleep 20
Send {m}
}
return

;Basic/Quick Camera Reset Function Setup
Cam: ;Basic camera reset function, remember to use "BlockInput MouseMoveOff" after it
{
BlockInput MouseMove
send {BS}
send {BS}
MouseClick,WheelDown,,,30,0,D,R
}
return

;Basic/Quick Camera Reset
+LAlt::
{
Gosub, Cam
BlockInput MouseMoveOff
}
Send {LAlt Up}
return

;Auto-reinforce
r::
Loop 10
{
Send {r}
Send {Tab}
}
return


;Vehicle click-queue script
MButton::
Send {Rbutton}
Send {Shift Down} ;Delete this line if you don't want 1st click to be priorized.
Loop
{
if not GetKeyState("MButton", "P")
break
Send {Rbutton}
sleep 20 ;sets delay between clicks
}
Send {Shift Up}
return

;------------------------------------------------------

return


Full script, with all Auto-Reinforce code removed
Spoiler

;Initialisation
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
Process, Priority, , High

;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
; ChatMode
;Author: Xalard
;Don't touch this part unless you know what you are doing.
; Parameters:
; list1 = mapped keys list
; list2 = hotkeys list
; mode:
; on - hotkeys DISABLED
; off - hotkeys ENABLED
; toggle

ChatOff: ;-needed to toggle chat off on mouse click
ChatMode(mapped, hotkeys, "off")

ChatMode(list1, list2, mode = "toggle")
{
static
; space removal
StringReplace, list1, list1, %A_Space%,,All
StringReplace, list1, list1, &,%A_Space%&%A_Space%,All ;fix for custom key combinations using &
StringReplace, list2, list2, %A_Space%,,All
StringReplace, list2, list2, &,%A_Space%&%A_Space%,All
; translate the "mode" argument to one to use with "Hotkey" function and set chat status
if mode = toggle
{
mode_hk = toggle
chat := !chat
}
else if mode = on
{
mode_hk = off
chat := 1
}
else if mode = off
{
mode_hk = on
chat := 0
}
else MsgBox, %mode% is not a valid parameter for ChatMode function!
; execute all necessary "Hotkey" commands
if list2 != ""
{
loop, parse, list2, `,
{
Hotkey, %A_LoopField%, %mode_hk%
}
}
if list1 != ""
{
loop, parse, list1, `,
{
Hotkey, *%A_LoopField%, %mode_hk%
Hotkey, *%A_LoopField% up, %mode_hk%
}
}
; Prevent mouse from fucking up the script
If chat = 0
{
Hotkey, ~*LButton, ChatOff, off
Hotkey, ~*RButton, ChatOff, off
Hotkey, ~*MButton, ChatOff, off
Hotkey, ~*WheelUp, ChatOff, off
Hotkey, ~*WheelDown, ChatOff, off
}
Else
{
Hotkey, ~*LButton, ChatOff, on
Hotkey, ~*RButton, ChatOff, on
Hotkey, ~*MButton, ChatOff, on
Hotkey, ~*WheelUp, ChatOff, on
Hotkey, ~*WheelDown, ChatOff, on
}
}
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Due to the way AHK handles global variables, hotkeys to toggle for the chat
; compatibilty have to be declared BEFORE the hotkeys themselves are set
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


; HOTKEYS
;Declare all hotkeys you want disabled when chatting

; CLOSING CHAT BY USING MOUSE BUTTONS
;This script will still work correctly if you use mouse click or scrollwheel to close the chat
;If you don't declare your mouse hotkeys below, the script might break if you use them when chatting


; Guidelines for listing keys in this section:
; separate keys using a comma ,
; modifiers such as in ~*Tab or !BS also have to be listed
; spaces are automatically removed
; if you have no keys to declare, leave the variable blank, eg. mapped := ""

; If you declare a hotkey that doesn't exist, the script will crash when you press Enter

;Declare all REMAPPED keys below:
; Remapped keys are keys that are coded like this:
; w::up
; Space::Numpad0
mapped := "w,a,s,d,q,e,t,y,u,f,CapsLock,h"

;Declare all other hotkeys below:
hotkeys := "MButton,n,k,l,m,+LAlt"

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ALL hotkeys must be placed below this line
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

F9:: ;always on, in case #IfWinActive refuses to work
Suspend Off
SoundBeep
Reload
return

;======================================================
#IfWinActive, Company Of Heroes

;Suspend
F11::
SoundBeep, 1750, 800
Suspend On
return

;------------------------------------------------------

;ChatMode
~*NumpadEnter::
~*Enter::ChatMode(mapped, hotkeys, "toggle")
~*Esc::ChatMode(mapped, hotkeys, "off")
;/Chatmode

;------------------------------------------------------

;Arrow keys
w::up
a::left
s::down
d::right

;Tac Map
q::Numpad0

;Retreat
e::t

;Grenade
t::n

;Sticky Bomb
y:: s

;Unload
u:: d

;Attack move
f::a

;Hold Fire
h:: d

;HALT!
CapsLock::h

;------------------------------------------------------

;Quick Lay - Sand Bags
n::
{
Send {b}
sleep 20
Send {s}
}
return

;Quick Lay - Tank Traps
k::
{
Send {b}
sleep 20
Send {t}
}
return

;Quick Lay - Wire
l::
{
Send {b}
sleep 20
Send {w}
}
return

;Quick Lay - Mine
m::
{
Send {b}
sleep 20
Send {m}
}
return

;Basic/Quick Camera Reset Function Setup
Cam: ;Basic camera reset function, remember to use "BlockInput MouseMoveOff" after it
{
BlockInput MouseMove
send {BS}
send {BS}
MouseClick,WheelDown,,,30,0,D,R
}
return

;Basic/Quick Camera Reset
+LAlt::
{
Gosub, Cam
BlockInput MouseMoveOff
}
Send {LAlt Up}
return

;Vehicle click-queue script
MButton::
Send {Rbutton}
Send {Shift Down} ;Delete this line if you don't want 1st click to be priorized.
Loop
{
if not GetKeyState("MButton", "P")
break
Send {Rbutton}
sleep 20 ;sets delay between clicks
}
Send {Shift Up}
return

;------------------------------------------------------

return


THE END
or
"Th-th-th-that's all folks!"



thumb.gif



EDIT(03/08/12): Fixed unintended syntax errors found in the script, which occurred when it was transfered from notepad to the thread.

This post has been edited by RampageCrumpet: Aug 3 2012, 00:57 AM

Posts: 102

Game: Company of Heroes

+
# 178yesyamaha Apr 29 2012, 08:06 AM
Well I think I will remove the auto reinforce part. Its not that I think its cheating or something that gives you an unfair advantage but its just that it has some downsides as well (like draining all ur mp pretty fast especially when US) and I dont want them right now. So do I just delete the
CODE
  
;Auto-reinforce
r::
Loop 10
{
Send {r}
Send {Tab}
}
return



part and use the rest or more will have to be done?

This post has been edited by yesyamaha: Apr 29 2012, 08:10 AM

Posts: 95

Game: Company of Heroes 2

+
# 179Xalard Apr 29 2012, 08:14 AM
Delete what you quoted then edit

hotkeys := "MButton,r,n,k,l,m,+LAlt"

into

hotkeys := "MButton,n,k,l,m,+LAlt"

Posts: 1,015

Game: Company of Heroes

+
# 180RampageCrumpet Apr 29 2012, 13:13 PM
Yesyamaha

I have included your question as a working example in my advanced tutorial section. Feel free to check there if you are still unsure.







On that: God damn that took a while to write haha!

Posts: 102

Game: Company of Heroes

+

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)