Jump to content


Photo

"Hard Macro" macro tool for mouse


  • Please log in to reply
16 replies to this topic

#1 Laufer

Laufer
  • Members
  • 54 posts

Posted 25 March 2012 - 04:30 PM

Good news everyone! :)

I'd like to present my work! This is a script that allows you to program various actions and assign them to your mouse buttons.

Posted Image

Here are the advantages of the script:
+ Unlimited quantity of profiles (Corsair software allows only 1)
+ Fast switch between profiles. Just press Win+Z (Corsair soft must be launched, switched to profile via interface and reloaded to mouse memory)
+ Application assignment. Profile will work in windows requested (In fact Corsair doesn't recognize different applications)
+ Functionality of macros limited only with your imagination (Corsair soft not allows mouse button pressing in macros. Also not allows cycles, pre-pressing, post-pressing and so on)
- But this script requires some patience! So, go on and get some and welcome to the club! 8)

:!: Script has been tested with M60 Corsair mouse but also may be used for almost every mouse with 8 or less buttons and vertical scroll wheel.

Let's begin!


Step 1. Assign extended mouse buttons

You need to assign them to hardcoded buttons (listed below). Its a bit lame, but you have to do it only once.
1. Mouse button 4 assign to Numpad 4
2. Mouse button 5 assign to Numpad 5
3. Mouse button 8 assign to Numpad 8 (example on screen below)

Posted Image

:!: If you still want to use some specific mouse button don't assign it. It will be ignored by the script. I personally don't assign mouse button 5, I set it to DPI Select

Step 2. Install script software

1. Install AutoHotkey_L Installer
2. Download and unpack anywhere HardMacro (script, images, example macros)
3. Download SciTE4AutoHotkey - delux macro editor. (This download is optional, Windows notepad.exe will be enough)

Step 3. Create new profile

1. Run script HardMacro.ahk from previously downloaded Hard Macro package

Posted Image

2. Press button "Create profile" and input name of new profile.
3. Select macro from drop-down lists (blue numbers correspond to mouse buttons).

Step 4. Get application window name

1. Press "Get application window name" button. Window spy will be launched.
2. Open your application where you will use macros in windowed mode.
3. Switch to application and Window spy will show something like that (on screen below there is the window information of Battlefield Heroes game shown):

Posted Image

4. Copy window name from section ">>>>>>(Window Title & Class)<<<<<<". You will need part of name displayed after ahk_class (underlined with red).
5. Paste window name to the field Application of Hard Macro window.

Step 5. Edit macros

1. Press button "Edit macro" on the right of drop-down lists with macro names. Macro will be open for editing.
2. When you finish editing just save script and close editor.
3. If you want to create new macro create new .ahk file in Macros folder. When new macro created restart Hard Macro.
:!: Macro's file name must match label name of this macro's subroutine. Thus macro 5_Run_Heal.ahk has subroutine named 5_Run_Heal:

4. Press "Save" button. Profile will be saved to HardMacro.ini.
5. Press "Launch" button. Hard Macro will generate and run script MacroScript.ahk. Icon Posted Image will be shown in your system tray. If you want to stop script press right mouse button on that icon and select "Exit".
6. Press Win+Z to switch between profiles.

Thats it!
Thank you for attention. Have fun! :wink:


p.s. If you found a bug or have some ideas about my program - let me know!

_________________
To Do list:
1. Add "Create macro" button for every drop-down list. Giving to user a list of templates so will be easier to create new macro.
2. Version for M90 Corsair mouse (if anyone be interested)
3. Switch between profiles inside one application
4. Sounds when mouse over and buttons clicks
5. Keyboard macros

#2 Laufer

Laufer
  • Members
  • 54 posts

Posted 25 March 2012 - 04:31 PM

Macro commands explained

So lets go a bit further to the forest of Knowledge! I'll give you some simple examples in order to get the main idea of macro coding.

Posted Image 1. Single key press

Lets make first small step and make the same thing that you can do in every mouse software. Single key press!

Posted Image

Push "Record macro" button and press some key (in our case key "Q"). The result is on the screen above. Three lines show:
1. Press Q button
2. Wait 0,050 seconds
3. Depress Q button

How it looks in macro code? Create file q_PressOnce.ahk in folder \Macros and input there something like that:
; Text to the right from semicolon is commentary
;
; Single key press
q_PressOnce:     ; Subroutine name. It must be the same as filename!
	Send {q down} ; Press Q button
	Sleep, 50     ; Wait 50 milliseconds
	Send {q up}   ; Depress Q button
return           ; Every subroutine must be finished with that command
Here I use Send command to emulate key pressing and Sleep command for pause. If you want to make a macro for another key, replace "q" with some other letter or number. If you want a key to be pressed longer replace Sleep parameter "50" with some other value.

Posted Image 2. Number of key presses

Where are two ways to make a number of key presses.
First: copy code. Below follows the example:
; Press Space three times by coping
;
Space_KeyPressByCoping:
	Send {Space down} ; press first time
	Sleep, 50
	Send {Space up}
	Sleep, 50
	Send {Space down} ; press second time
	Sleep, 50
	Send {Space up}
	Sleep, 50
	Send {Space down} ; press third time
	Sleep, 50
	Send {Space up}
	Sleep, 50
	Send {Space down} ; press fourth time
	Sleep, 50
	Send {Space up}
	Sleep, 50
return
Second: make cycle.
; Press Space three times by cycle
;
Space_KeyPressByCycle:
	Loop, 4 ; loop count
	{
		Send {Space down}
		Sleep, 50
		Send {Space up}
		Sleep, 50
	}
return
In the last example I used Loop command for cycle.

Posted Image 3. Repeat while pressed

There are two ways to process a key press while pressed.
First: broken presses.
; Press Left Mouse Button (LMB) repeatedly while Right Mouse Button (RMB) is pressed
;
LMB_Intermittent:
	while GetKeyState("RButton", "P") ; while RMB pressed
	{
		Send {LButton down}            ; press LMB
		Sleep, 50
		Send {LButton up}
		Sleep, 50
	}
return
Here I used While command for conditional cycle and GetKeyState to find out if key pressed or not.

Second: continuous pressing.
; Press Left Mouse Button repeatedly while Right Mouse Button is pressed
;
LMB_Continuous:
	Send {LButton down}               ; press LMB
	while GetKeyState("RButton", "P") ; hold LMB pressed while RMB pressed
	{
	}
	Send {LButton up}                 ; depress LMB
return

Posted Image 4. Toggle key press

Next example shows If-Else construction and new command: SetTimer. It calls subroutine v_ToggleTimer every 75 ms. Also we implicitly declare variable ToggleFlag. Macro seems hard to understand so just replace parameter of Send command.
This macro may be useful for voice programs to toggle Push-to-Talk mode:
; Press assigned button to toggle key "V" state
;
v_Toggle:
	If ToggleFlag ; If variable contents are blank (by default) or 0, it is considered false. Otherwise, it is true.
	{
		SetTimer, v_ToggleTimer, Off ; Turn off timer if button's been pressed second time
	}
	else
	{
		SetTimer, v_ToggleTimer, 75  ; Set timer to run every 75 milliseconds
	}
	ToggleFlag := not ToggleFlag    ; Invert variable (if it has true make it false and vice versa)
return

v_ToggleTimer:
	Send {v down} ; Send key press
return


Conclusion
This four examples covers mostly all of your needs in macros. Simply replace key notation in the code and rename subroutines (don't forget to keep them the same as macro filenames!). Try to combine this methods and will get more impressive results! For example, can you do it with any user-friendly mouse software?:

; Macro: "1" + (LMB) + BB`1 + Heal`4
;
; + Switch to weapon "1"d
; + Fire holding LMB
; + Turn on Burning Bullets (press "7") after 1 second holding (after time passed push BB button every 0.5 sec)
; + Heal (press "5") after 4 second holding (after time passed push Heal button every 0.5 sec)
1LMB75_Switch1FireBBHeal:
	Send {1 down}              ; Press "1"
	Sleep, 50
	Send {1 up}
	SetTimer, BB_on, -1000     ; Set BB timer for 1 second
	SetTimer, Heal_on, -4000   ; Set Heal timer for 4 seconds
	Key := % A_ThisHotKey      ; Use that construction to make macro universal. Guess why! ;)
	StringReplace, Key, Key, *$, , All
	Send {LButton down}        ; Push and hold LMB
	while GetKeyState(Key, "P")
	{
	}
	Send {LButton up}          ; Release LMB
	SetTimer, BB_on, Off       ; Turn off timers
	SetTimer, Heal_on, Off
return

; Burning Bullets timer activated
BB_On:
	Send {7 down} ; Press "7"
	Sleep, 50
	Send {7 up}
	SetTimer, BB_on, -500
return

; Heal timer activated
Heal_On:
	Send {5 down} ; Press "5"
	Sleep, 50
	Send {5 up}
	SetTimer, Heal_On, -500
return

Still want more? Read fine AutoHotkey manual, read this forum, experiment, be curious!

May the Force be with you! 8)

#3 Carrozza

Carrozza
  • Members
  • 199 posts

Posted 26 March 2012 - 07:37 AM

Excellent script and professional introduction.
Bravo! ^__^

#4 Laufer

Laufer
  • Members
  • 54 posts

Posted 26 March 2012 - 08:44 AM

Thank you Carrozza, I do my best! Hope script will be usefull :)

Uploaded my script on AutoHotkey.net hosting. Thank you, sumon! :idea:

#5 neXt

neXt
  • Members
  • 533 posts

Posted 27 March 2012 - 01:49 AM

Wow, really nice looking work. I'll test it out right now.
Not sure if this is implemented, but in my mouse for games script I included tripple mouse clicks for various actions. For instance in CNC3, I place a beacon by pressing right button three times. Ignore this if it's already there, if not, then something neat to implement :wink:

#6 tomoe_uehara

tomoe_uehara
  • Members
  • 2077 posts

Posted 27 March 2012 - 02:46 AM

Yes, I have to agree, this project has a very nice GUI, I've never see like this before

#7 Laufer

Laufer
  • Members
  • 54 posts

Posted 27 March 2012 - 05:48 AM

tomoe_uehara, I spent 5% time on coding, 15% on testing and 80% time on creating nice looking GUI :shock:
I'm glad that you like it :)

neXt, its easy to make whatever you want. None of mouse user-friendly software can be compared with power of pure code! :twisted:
I'll post example part of macro coding this evening :wink:

#8 Guests

  • Guests

Posted 27 March 2012 - 05:51 AM

It's so Great! Thanks you very much! :D

#9 Laufer

Laufer
  • Members
  • 54 posts

Posted 27 March 2012 - 07:12 PM

Added some macro coding examples. Check them out :)

#10 DataLife

DataLife
  • Members
  • 730 posts

Posted 25 August 2012 - 12:26 PM

Does anyone have a copy of this?

#11 Laufer

Laufer
  • Members
  • 54 posts

Posted 25 August 2012 - 02:20 PM

I got it :). Do you know any good file hosting?

upd: Updated link to new host. If you know something better - let me know.

#12 DataLife

DataLife
  • Members
  • 730 posts

Posted 25 August 2012 - 05:40 PM

I got it :). Do you know any good file hosting?

upd: Updated link to new host. If you know something better - let me know.


<!-- m -->http://WWW.dropbox.com<!-- m --> is very easy to use. It creates a Dropbox folder on your computer, and anything in that folder gets copied to the online dropbox. To share files you have to put the files in the "Public" folder and then on the dropbox website navigate to your file and right click and choose "Copy public link". That is the download url to your file.

#13 Laufer

Laufer
  • Members
  • 54 posts

Posted 25 August 2012 - 06:16 PM

...<!-- m -->http://WWW.dropbox.com<!-- m --> is very easy to use...

Awesome stuff, dude! Thank you very much!
Updated first post.

#14 Aljo

Aljo
  • Members
  • 1 posts

Posted 30 August 2012 - 01:08 AM

I cannot get it to work with my Logitech MX518 I have a feeling the setpoint driver is not compatible but I am not sure

#15 Laufer

Laufer
  • Members
  • 54 posts

Posted 30 August 2012 - 05:45 AM

Did you assigned additional buttons to numpad keys as described in first post?
Actually, my script don't work with driver - it just catches mouse button and numpad key pressings and reassign it to custom script.