Register    Login    Forum    Search    FAQ Awesomenauts



Post new topic Reply to topic Go to page 1, 2, 3  Next

Author Message
 Post subject: AwesomenautsKeyBinder - Chat Macro
 Post Posted: Sat Sep 06, 2014 3:36 pm 
Offline
User avatar

Joined: Wed Aug 20, 2014 9:10 pm
Posts: 35
Location: France
As someone who likes to type relatively long, descriptive sentences in chat, it often frustrates me that the fast pace of the game prevents me from expressing myself fully. In Source engine games, it's possible to bind certain key or key combinations to chat messages, which I think is a really useful feature.

AwesomenautsKeyBinder emulates this functionality by having a small Windows-only Python script run in the background, listening for key presses. When a certain key is pressed, it'll virtually press the keys required to send out a pre-written message in team or global chat (as desired). Basically, it lets you quickly send messages to either your teammates or to every player.

This is just a really simple script that I wrote in a few hours; I might improve it later on. It might be a bit buggy or fiddly, so, just to be safe, stop moving your character when you press the key (in my testing, some letters got dropped or the message got garbled under certain conditions).

Download Link: AwesomenautsKeyBinder.zip

To use it, unzip the file somewhere on your computer. In the AwesomenautsKeyBinder folder, you'll see several files; you only need to concern yourself with two of them:
  • AwesomenautsKeyBinder.ini: the configuration file for the script. Write your chat binds in here. I've included a few demo lines in there.
  • AwesomenautsKeyBinder.exe: when you have configured your chat lines, launch this program and click on "Run". You can press on "Halt" at any time to stop listening for key combinations. Then, while in an Awesomenauts match, press your chosen key to send out the message.

I haven't tested this on any machine but my own, but I think it should run out of the box. If not, please send me any error message that appears.

If you're interested in the source code, here it is:
Code:
# AwesomenautsKeyBinder
# Script
#
# Installation and Usage:
# 1) Install Python 2.7 32-bit (https://www.python.org/download/releases/2.7/).
# 2) Install pyHook for Python 2.7 32-bit (http://sourceforge.net/projects/pyhook/files/pyhook/1.5.1/).
# 3) Install Python for Windows extensions for Python 2.7 32-bit (http://sourceforge.net/projects/pywin32/files/pywin32/).
# 4) Install pyUserInput (https://github.com/SavinaRoja/PyUserInput/wiki/Installation).
# 5) Launch 'AwesomenautsKeyBinder.pyw'.
# To customize, edit 'AwesomenautsKeyBinder.ini'.

from ConfigParser import SafeConfigParser
import os.path
import time
from Tkinter import *
from ttk import *

from pykeyboard import PyKeyboard
import pyHook


class AwesomenautsKeyBinder(Frame):
    """
        Used to bind Awesomenauts chat lines to keys.
    """

    TITLE = "Awesomenauts Key Binder"
    CONFIG_FILE = "AwesomenautsKeyBinder.ini"
   
    def __init__(self, master=None):
        """
            Initialize the keyboard instance and an empty bind list.
        """
       
        Frame.__init__(self, master)
        self.master.title(self.TITLE)
        self.master.minsize(width=300, height=30)
        self.pack()
        self.setup_widgets()
       
        self.k = PyKeyboard()
        self.hm = pyHook.HookManager()
        self.hm.SubscribeKeyDown(self.on_key_down)
        self.hm.HookKeyboard()

        self.binds = {}
        self.isRunning = False
        self.isTyping = False
       
        self.read_config(self.CONFIG_FILE)

    def read_config(self, path):
        """
            Reads the configuration from a file.
        """
       
        self.config = SafeConfigParser()
        self.config.read(path)
        if self.config.has_section("KeyBindings"):
            for option in self.config.options("KeyBindings"):
                if option.endswith("_team"):
                    continue
                self.bind(
                    option,
                    self.config.get("KeyBindings", option),
                    self.config.get("KeyBindings", option + "_team").lower() == "true"
                )
       
    def setup_widgets(self):
        """
            Sets up the window's widgets.
        """
       
        self.run_button = Button(self, text="Run", command=self.run)
        self.run_button.grid(row=0, column=1)
        self.halt_button = Button(self, text="Halt", command=self.halt, state=DISABLED)
        self.halt_button.grid(row=0, column=0)
       
    def bind(self, key, message, team=True):
        """
            Binds a message to the specified key.
        """
       
        self.binds[str(key).lower()] = (message, team)

    def on_key_down(self, event):
        """
            Called when a key is pressed.
        """
       
        if self.isRunning and not self.isTyping:
            try:
                bind = self.binds[event.GetKey().lower()]
                self.say(*bind)
                return False
            except KeyError:
                return True
        return True

    def say(self, message, team=True):
        """
            Sends the key events required to send a message in chat.
        """
       
        self.isTyping = True
        if not team:
            self.k.press_key(self.k.shift_key)
        self.press_enter()
        if not team:
            self.k.release_key(self.k.shift_key)
        for c in message:
            self.k.press_key(c)
            self.k.release_key(c)
        self.press_enter()
        self.isTyping = False

    def press_enter(self):
        """
            Awesomenauts is a bit fiddly when it comes to Enter.
            This makes sure it gets registered correctly.
        """
       
        self.k.press_key(self.k.enter_key)
        time.sleep(0.1)
        self.k.release_key(self.k.enter_key)
       
    def run(self):
        """
            Starts listening for key events.
        """
   
        self.isRunning = True
        self.run_button.config(state=DISABLED)
        self.halt_button.config(state=NORMAL)
   
    def halt(self):
        """
            Stops listening for key events.
        """
       
        self.isRunning = False
        self.halt_button.config(state=DISABLED)
        self.run_button.config(state=NORMAL)

if __name__ == "__main__":
    root = Tk()
    app = AwesomenautsKeyBinder(master=root)
    app.mainloop()

_________________
Lyrositor
"I honestly think you ought to sit down calmly, take a stress pill and think things over."
Steam - add me if you want to play together!
Website

Main: Voltar


Last edited by Lyrositor on Sun Sep 07, 2014 8:46 am, edited 2 times in total.

Top 
 Profile  
 
 Post subject: Re: AwesomenautsKeyBinder - Chat Macro
 Post Posted: Sat Sep 06, 2014 4:13 pm 
Offline
User avatar

Joined: Thu Jul 24, 2014 5:54 pm
Posts: 3302
Just imagine. Telling your teammates if the enemy is going to attack top or bottom by pressing a key while fighting.

_________________
Steam
Nauts Videos!

Carl wrote:
This game made me xenophobic. I was buying wine once, I almost bought one then realized it was from Argentina. I grabbed an American wine instead


StarDasher wrote:
This game has made me racist.
I block every single japanese people i encounter.


Top 
 Profile  
 
 Post subject: Re: AwesomenautsKeyBinder - Chat Macro
 Post Posted: Sat Sep 06, 2014 4:20 pm 
Offline
Adminaut
User avatar

Joined: Mon Aug 19, 2013 11:03 pm
Posts: 10371
Location: Tech-Support. . . E-mail: sir.emo.chap@gmail.com
Now watch as someone binds an actual taunt into chat to their taunt button. :rae:


Top 
 Profile  
 
 Post subject: Re: AwesomenautsKeyBinder - Chat Macro
 Post Posted: Sat Sep 06, 2014 4:25 pm 
Offline
User avatar

Joined: Sun May 18, 2014 12:33 pm
Posts: 1832
Location: Great Sausage Country
Emo Chapington wrote:
Now watch as someone binds an actual taunt into chat to their taunt button. :rae:

Or worse, to their wasd buttons.

"You should have left."
"I am always right."
"Up I go!"
"You're going down!"


Top 
 Profile  
 
 Post subject: Re: AwesomenautsKeyBinder - Chat Macro
 Post Posted: Sat Sep 06, 2014 4:35 pm 
Offline
User avatar

Joined: Wed Dec 11, 2013 10:29 am
Posts: 1285
Location: France
Awesome, can't wait to bind my "hai", "good fun have luck" and my "'SUP INTERNET PPL"

_________________
[ YouTube Hype Channel ] - [ VolyArts Thread ] - [ Steam ] - [ Twitter ]

♥    :party:    ♥    :facepalm:    ♥   :ksenia: ♥    :shady:    ♥    :yoolip:    ♥    :chucho:    ♥


Top 
 Profile  
 
 Post subject: Re: AwesomenautsKeyBinder - Chat Macro
 Post Posted: Sat Sep 06, 2014 5:30 pm 
Offline

Joined: Sat May 24, 2014 7:51 pm
Posts: 1117
Location: Lithuania, EU
Ten_Tacles wrote:
Emo Chapington wrote:
Now watch as someone binds an actual taunt into chat to their taunt button. :rae:

Or worse, to their wasd buttons.

"You should have left."
"I am always right."
"Up I go!"
"You're going down!"

LMAO :lolstar:

_________________
Awesomenauts are doomed forever to have a small community!
Steam | Vinnie rework (v2.9) | Derpl rework (v2.11)

in <3 with: :drool: :shrug: :think:


Top 
 Profile  
 
 Post subject: Re: AwesomenautsKeyBinder - Chat Macro
 Post Posted: Sat Sep 06, 2014 5:40 pm 
Offline
User avatar

Joined: Tue Aug 07, 2012 1:43 am
Posts: 1495
+1 for using python, started learning it myself last December and it has become the cornerstone of many of my personal projects (including the shady ones that make ronimo hate me).

As for the script itself, I tested it on notepad and it seems to be as fast as autohotkey, so I might replace it. My only suggestion is to get rid of the tk dependency and just use the system tray, you can use this library which was based on this script, or you can adapt the script yourself.

How long did it take to figure the enter key thing out? I spent an whole hour messing with my ahk script until it hit me what was going on.


Top 
 Profile  
 
 Post subject: Re: AwesomenautsKeyBinder - Chat Macro
 Post Posted: Sat Sep 06, 2014 5:47 pm 
Offline
User avatar

Joined: Wed Aug 20, 2014 9:10 pm
Posts: 35
Location: France
Nodja wrote:
As for the script itself, I tested it on notepad and it seems to be as fast as autohotkey, so I might replace it. My only suggestion is to get rid of the tk dependency and just use the system tray, you can use this library which was based on this script, or you can adapt the script yourself.

Thanks for the library, it's a good suggestion. I'll try to implement it for the next version - hopefully, that'll let me get rid of the annoying Tcl folder.

Nodja wrote:
How long did it take to figure the enter key thing out? I spent an whole hour messing with my ahk script until it hit me what was going on.

Right after the first (failed) try, actually. :rae: I figured the game's input loop checked for input less frequently when it wasn't in text entry mode (it doesn't need to anyway), so I tried "pressing down" on Enter a bit longer and it worked. I wondered if I could make the pause shorter, but I figured it wouldn't be worth it, as it was hardly noticeable already and it might negatively impact people playing with lower FPS (since the input would be checked less frequently).

_________________
Lyrositor
"I honestly think you ought to sit down calmly, take a stress pill and think things over."
Steam - add me if you want to play together!
Website

Main: Voltar


Top 
 Profile  
 
 Post subject: Re: AwesomenautsKeyBinder - Chat Macro
 Post Posted: Sat Sep 06, 2014 5:49 pm 
Offline
Adminaut
User avatar

Joined: Mon Aug 19, 2013 11:03 pm
Posts: 10371
Location: Tech-Support. . . E-mail: sir.emo.chap@gmail.com
I was recently experimenting on making my own macro program in Python, so this is actually quite helpful to me :ayla:

If i might ask: why is the folder (Uncompressed) so large? The contents seems to total 3MB, but it says that in total there is 10.6MB worth :huh:

Edit:
When you say use "NUMPAD0 to NUMPAD9", I assume that requires Num Lock to be on? :chew:


Top 
 Profile  
 
 Post subject: Re: AwesomenautsKeyBinder - Chat Macro
 Post Posted: Sat Sep 06, 2014 6:02 pm 
Offline
User avatar

Joined: Wed Aug 20, 2014 9:10 pm
Posts: 35
Location: France
Emo Chapington wrote:
I was recently experimenting on making my own macro program in Python, so this is actually quite helpful to me :ayla:

If i might ask: why is the folder (Uncompressed) so large? The contents seems to total 3MB, but it says that in total there is 10.6MB worth :huh:

I can think of only two major limitations to using Python: slower execution speed and larger bundled applications. The reason why it's so big is that my app packages the entire Python runtime, as well as some relatively large libraries. If I remove the graphical interface, this should free up about 6 MB.

Emo Chapington wrote:
Edit:
When you say use "NUMPAD0 to NUMPAD9", I assume that requires Num Lock to be on? :chew:

That's right (and a numpad :shady: ); if you want to just use the number keys above letter names, just use "1" through "9".

_________________
Lyrositor
"I honestly think you ought to sit down calmly, take a stress pill and think things over."
Steam - add me if you want to play together!
Website

Main: Voltar


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic Go to page 1, 2, 3  Next