PDA

View Full Version : Command / key-press macros



mr_belowski
11-02-2017, 04:02 PM
Guys,

In the latest release we've added the ability to send sequences of key presses from the app to the game (PC only), in response to voice commands (or in a couple of special cases, triggered by events in the game). This is all a work in progress and has no pretty user interface - it's all driven by a configuration file.

The app includes some common macros for Raceroom and ProjectCars2, but I expect the list to grow (a lot), so if there are any common sequences of key presses you're having to make to do stuff in-game these could be incorporated into the default macro configuration. Stuff like requesting a pit stop, selecting pit actions, etc.


Here's the text from the help file, which explains it a bit more:

Command macros
--------------
The app can send sequences of key presses in response to voice command or some specific (hard-coded) in-game events. These can be used for anything you like, but their primary function is to ease the pain of navigating the awkward in-game pit menus. The app comes with a default set of command macros which (at the time of writing) are for PCars2 and Raceroom only. More will be added for other games. The default commands can be found in [install folder]/saved_command_macros.json. If you want to make your own, copy this file to a your Documents folder, in a subfolder called CrewChiefV4 (i.e. Documents/CrewChiefV4/saved_command_macros.json) and edit it as you like.


The first thing you need to do is to update your key assignments in-game so they match the keys that the command macro will send.




Raceroom


default key bindings:
"Pit Menu Toggle": q
"Pit Menu Select": e
"Pit Menu Up": w
"Pit Menu Down": s
"Pit Menu Decrease": a
"Pit Menu Increase": d
"Pit Request Toggle": r
"Real-time Chat": c


Ensure that there's a least one Pitstop Preset defined (from the in-game pit menu).


You can request a pit stop by saying "pit request", "in this lap" or "box this lap". This will open the pit menu, select 'pit request' and close it again after a few seconds delay. When you enter the pitlane the app will automatically open select 'confirm pit actions' from the pit menu so you don't have to fumble around.


You can also cycle pit presets with the voice commands "next strategy", "next pit preset", "previous strategy", "previous pit preset".


If you want to manually navigate the pit menu with voice commands, use "pit menu toggle", "pit menu up", "pit menu down", "pit menu left", "pit menu right" and "pit menu select".




PCars2


default key bindings:
"Car Management": e
"ICM Menu Up": w
"ICM Menu Down": s
"ICM Menu Left": a
"ICM Menu Right": d
"Pit Request Toggle": q
"In-game Chat Box": t


You can request a pit stop by saying "pit request", "in this lap" or "box this lap". This will open the pit menu, select 'pit request' and close it again.


You can select strategies with the voice commands "strategy one" / "strat one", up to "strategy four" / "strat four".


If you want to manually navigate the pit menu with voice commands, use "pit menu toggle", "pit menu up", "pit menu down", "pit menu left" and "pit menu right".



Advanced command macros
--------------

As you can see from the previous section, key press macros are complicated and a bit dumb - the app has no idea what state the pit menu is in so it has to either make lots of assumptions or work quite hard to put the menu into a known state.


There are 2 macros for adding fuel. In both cases, for them to work in R3E the selected pit preset must have fuel *selected* (i.e. highlighted green). One uses the logic of the app's 'Fuel' event to calculate how much fuel is needed to finish the race ("fuel to the end" voice command), the other uses the amount of fuel requested in the voice command ("add fuel, 100 litres" or whatever). These macros opens the pit menu, navigate to the fuel option and attempt to reset it to zero litres. Because they can't know how much fuel might already be set on this menu they have to press the 'decrease' button lots (150) times. This ensure it's at zero before they then add the calculated or requested amount of fuel.


*Note that these will only work correctly if you use Litres as your unit*.


Another point to note here is that these fuelling macros press 'decrease' 150 times quite quickly to ensure the fuel amount is zero before they start increasing it. When things are configured correctly it works well, but it's a lot of key presses and if something goes wrong the end result may be undesirable.


The macro feature can also be used to automate chat messages. There are examples for pCars2 and R3E. Again, these just send sequences of key presses.


There are a few special key press commands in save_commands_macros.json to help ease the pain of wiring these things up. The "actionSequence" element is the list of key presses. These usually refer to action items in the keyBindings section at the top of the file. However, they can also be plain keys - e.g. [..., "a", "b", "c", ...].


- To send a fixed number of multiple key presses use "{MULTIPLE,153}Pit Menu Decrease" (presses the Pit Menu Decrease key 153 times).
- To send a number of multiplekey presses based on some app logic, use "{MULTIPLE,Fuel}ICM Menu Right" (presses ICM Menu Right however many times the Fuel event told it to). This requires specific application code to work but i'm happy to take requests :).
- To send a number of multiple presses based on the voice command that triggered the macro, the voice command needs to use a special format with the number range to recognise in curly braces - e.g. "add fuel, {1,150} litres" (recognises "add fuel 0 litres" up to "add fuel 150 litres", in steps of 1). Use "{MULTIPLE,VOICE_TRIGGER}Pit Menu Increase" to press (in this example) Pit Menu Increase the number of times recognised in the voice command.
- To send a sequence of key presses from some free text, use "{FREE_TEXT}sorry, my bad". Each of the keys after {FREE_TEXT} will be pressed in sequence. Only letters, commas, hypens and full-stops are supported. This is to make chat macros more straightforward (e.g. ["Real-time Chat", "{FREE_TEXT}good pass", "ENTER"]).


The file saved_commands_macros.json in your app's installation folder has examples of all this stuff and lots of comments that should further demystify the process. Alternatively just get the correct in-game key bindings and just use the stuff I've already configured.

Hopefully the game devs will make these menus or the actions they trigger easier to use for 3rd party apps. But until they do, these complicated automated interactions are always going to be flaky.

Paul Bee
12-13-2017, 12:22 PM
I need help to understand this please.

I'm a sim racer of 'more mature years' and have, until now, restricted my racing activities to the PS4 platform, most notably with the original Project Cars and Crew Chief on an Android device. However, with some rather disappointing 'issues' in the new Project Cars release, I've made the move to a PC platform within the past 2 weeks and am currently in the middle of a very steep learning curve.

I downloaded Raceroom and have even managed to get Crew Chief set up..... The next phase, when December 25th comes along, will be my first venture in to VR and so I have read your post on voice commands with great interest.

Do I need to install and set up voice command software? Voice Attack or somesuch? I'm running Windows 10 which I believe has a voice command function. Should I spend time learning setting this up and when done, will I be able to adopt your voice command functions?

Any help would be much appreciated.

Thanks
Paul

mr_belowski
12-13-2017, 12:32 PM
Crew Chief voice recognition uses Microsoft Speech Recognition. This is *not* the same as Windows Speech Recognition. To use voice recognition with Crew Chief, you need to install the recognition engine:

https://www.microsoft.com/en-gb/download/details.aspx?id=27225

and then install a speech recognition language pack:

https://www.microsoft.com/en-gb/download/details.aspx?id=27224


that's all you need to do - no training or anything. You mic needs to be the default audio recording device.

Paul Bee
12-13-2017, 05:03 PM
Thank you. I'll look in to it.

Danny
02-17-2018, 02:02 AM
Mr. Belowski-
I wanted to be able to send messages in Assetto Corsa text chat using speech, so I forked the repository to find out how I could add that behavior. I thought GrammarBuilder.AppendWildcard() [or maybe DictationGrammar and SetDictationContext] might let me grab any text following some initial marker phrase (e.g., "Say "), and then I could use SendKeys() to send the keystrokes to AC.

This was until I found saved_command_macros.json

Is the design of saved_command_macros flexible enough to allow me to send arbitrary words as keystrokes to AC?

mr_belowski
02-17-2018, 07:46 AM
The speech recognition engine is grammar based, not trained. It's not designed to recognise free speech - you have to limit the stuff it listens for otherwise the search space becomes too big and it gets very unreliable.

If there is a fixed list of chat messages you want to send, then that can be done with saved_command_macros.

If you want free diction here, you'll need to integrate the windows built in speech recognition engine

gmerariu
02-17-2018, 02:58 PM
Hi my friend. Love your app.

I used DRE before but yours is much better. I also donated so uou can continue to enhance and aupport it. :]

One question related to macros. I use iracing and need to program 2 commands via voice or wheel button

1) tear off(to clean my visor). Default iracing keys are alt+t
2) trigger whipers. Default iacing is ctrl+shift+w

How do i do that in crew chief

mr_belowski
02-17-2018, 03:33 PM
If you need to assign an action to a key-combination (alt-t or whatever), CC doesn't (yet) support that. The macros are single-key press only.

If you want to reconfigure iRacing so your tear-off is triggered by, say, just the 't' key, you'd need to add this key to the iRacing key bindings:



{
"description": "iRacing command mappings - these are the key assignments in the Options -> Controls",
"gameDefinition": "IRACING",
"keyBindings" : [
{
"action": "Lap Timing Black Box",
"key": "F1"
},
.....
{ "action": "Tear off",
"key": "KEY_T"
}



and then make a macro in the 'macros' section:



{
"name": "Tear off",
"description": "Presses T",
"voiceTriggers": [ "tear off" ],
"commandSets": [
{
"description": "iRacing only",
"gameDefinition": "IRACING",
"actionSequence": [ "Tear off" ],
"keyPressTime": 10,
"waitBetweenEachCommand": 200
}]
},
.....

gmerariu
02-17-2018, 07:27 PM
Thanks a million.

It's almost there.

I rather not change the default since it's used across multiple of my apps...

I can wait. Your app is getting better and better...for now, I am running voice attack simultaneously to send a few extra commands...

jtfreels
02-28-2018, 11:55 PM
I've attempted to add the "tear off" comand like the example above, it kinda works but doesn't actually do the tear off.
I have the "T" key configured in options to do the visor tear off.
Thanks for any help of what I've done wrong, details are below\

Jay

When I start Crew Chief I get this


17:41:00.523 : Loading user-configured command macros from Documents/CrewChiefV4/ folder
17:41:00.716 : Action Tear off not recognised
17:41:00.720 : Loaded 17 macro voice triggers into the speech recogniser



then when I say "tear off" I get

17:58:53.887 : recognised : tear off confidence = 0.9245504
17:58:53.895 : Sending actions Tear off

so it "works" I think, but the visor tear off does not occur in iRacing

what I've configured in my json file

{
"action": "Tear off",
"key": "T"
},

.....
and the macro part

{
"name": "Tear off",
"description": "Presses T",
"voiceTriggers": [ "tear off" ],
"commandSets": [
{
"description": "iRacing only",
"gameDefinition": "IRACING",
"actionSequence": [ "Tear off" ],
"keyPressTime": 10,
"waitBetweenEachCommand": 200
}]
},

mr_belowski
03-01-2018, 07:53 AM
Your key name is wrong - "key": "T" should be "key": "KEY_T"

jtfreels
03-01-2018, 04:07 PM
Great! Works perfectly now....

"someone" should edit post #8 and correct the example :)

Thanks again.

mr_belowski
03-01-2018, 04:19 PM
Ah yes, sorry about that, I've updated it :)

pablereitor
05-15-2018, 04:23 PM
What GameDefinition key text needed to use for rFactor2 ?

Tks.

The Iron Wolf
05-15-2018, 05:35 PM
Try RF2_64BIT please.

pablereitor
05-15-2018, 07:34 PM
Try RF2_64BIT please.


ยก Yeah, it works perfect !

sorry for my bad english.

Neil Bateman
05-15-2018, 08:53 PM
Hi jim, as I don't have a microphone at the moment is it possible for me to program a keypress for the fuel to end command until I can replace my mic, I cant figure out how to do it.

Thanks.

Neil Bateman
05-18-2018, 04:08 PM
Can anyone help with this, is it possible to request fuel calculation to end of race with a keyboard command or does it only work with voice command?

mr_belowski
05-18-2018, 04:25 PM
sorry, it's voice command only at the moment. I keep meaning to go back to that and finish it off, but haven't found the time yet

Neil Bateman
05-18-2018, 07:58 PM
OK tnx jim.:cool:

clintwood60
06-22-2018, 10:20 AM
Hi,
can I also transfer the keybinding (in "saved_command_macros.json") to the controller (Trustmaster T300)?
e.g .:
{
"action": "Pit Request Toggle",
"key": "KEY_Q"
},
to
{
"action": "Pit Request Toggle",
"wheel": "BUTTON_4"
}
Tnx for anwers
clintwood60

mr_belowski
10-05-2018, 07:40 AM
Unfortunately sending controller button presses isn't supported. I did want to implement it but it's hard - each game uses controllers in a different way and it can even vary by controller. So (for now at least) it's keyboard only.

I've made some significant changes to how the macros stuff works to simplify them and make them a bit more powerful - will be in the next released (see post 1 in this thread for the WIP documentation)

deloosem
12-01-2018, 08:47 PM
Can I also transfer NUMPAD 8 (not arrow UP)?

THx

Revan
12-30-2018, 07:46 PM
Hello guys,

i also want to assign a numpad key to an action, can you tell me please the syntax for that?

Found it via tiral and error:

you just have to use the ascii numbers for the specific key. In the case of numpad0 its the number 96 without the "key_"



{
"action": "Center HMD",
"key": "96"
},

mr_belowski
12-31-2018, 08:44 AM
have you tried using NUMPAD0 to NUMPAD9? That's how they're mapped in the code which generates keyboard input - it should be possible to do it like this:



{
"action": "Center HMD",
"key": "NUMPAD0"
}


you might need to ensure numlock is on for this to work

Revan
12-31-2018, 10:38 AM
Don`t know if i tried Numpad0 or key_Numpad0, there was quite a few combinations before i tried the ascii code.
As long as this works i`m happy :)

Thanks for helping out and have a nice new years eve

mr_belowski
12-31-2018, 10:42 AM
looking at the code, i honestly can't see how the ascii code could actually work

Revan
12-31-2018, 11:41 AM
Great :D

Don`t think about it, just accept...

When Life has chocolate to offer you better take it :)

Scoops
01-09-2019, 11:07 AM
Hi,

What would I need to add to the json file to bring macros to rF2?

I have tried adding

{
"description": "rFactor 2 command mappings - these are the key assignments in the Controller menu -> Game",
"gameDefinition": "rFactor 2 (64 bit)",
"keyBindings": [{
"action": "Open Chat",
"key": "KEY_T"
},

and added


{
"description": "rf2 version",
"gameDefinition": "rFactor 2 (64 bit)",
"actionSequence": ["Open Chat", "{FREE_TEXT}good pass", "ENTER"],
"keyPressTime": 10,
"waitBetweenEachCommand": 200
},


but the console is showing "No macro voice triggers defined for the current game" on loading. Loading as Race Room shows the macros loading?

What I am ultimately looking to do is to change my admin status and make admin calls in game such as remove penalties from other drivers etc from voice commands so once I can get the "good pass" test above working I'll be sorted.

Thanks

mr_belowski
01-09-2019, 11:37 AM
Game definition should be RF2_64BIT

Scoops
01-09-2019, 12:51 PM
Thanks, that's moved me on a bit. The console is now loading macro voice triggers into speech recogniser.

When I say "Chief" wait for the beep then say "say, good pass" the console recognises this

13:42:53.205 : Recognised : chat, say good pass confidence = 0.887

but then goes back to Waiting for trigger word chief. I only have rF2 but loded Race Room into CC and then started rF2 and opened the chat box to see if CC was sending key strokes and all works as it should.




I have just noticed the supported characters. Once I get y head around this can I send "/" to the chat window?

The full list of admins commands are

https://steamcommunity.com/sharedfiles/filedetails/?l=danish&id=580727258

and all require /

mr_belowski
01-09-2019, 02:05 PM
There are 2 ways to send key sequences - define each key press as its own action (like the pit macros do) or send free text, like the chat macros do.

The issue here is that there's no support for the '/' character in the chat macros. I'll add this (release due tonight or tomorrow). Alternatively you can use the long winded approach where each key press is an action. The front slash key is called OEM_2 or DIVIDE

Scoops
01-09-2019, 03:00 PM
Thanks DIVIDE is working fine.:) and I am so nearly there


If I want to set myself as admin in need to enter into the chat box for example

/admin Password123abc

I'm trying

"actionSequence": ["Real-time Chat", "DIVIDE", "{FREE_TEXT}admin Password123abc", "ENTER"]


and I'm getting a couple of issues

I can't get the upper case P (I could change the admin password on the server but if there is a way to get upper case that would be great.

The numbers don't display in the chat box.

The result is /admin passwordabc and then enter is pressed.

mr_belowski
01-09-2019, 03:22 PM
Upper case isn't supported - not sure how I'd do it to be honest. Can't see why numbers would work tho

Scoops
01-09-2019, 05:04 PM
I can get numbers using NUMPAD2 etc

As Caps Lock toggles on and off can that be used as a key press? "CAPITAL" isn't currently working, is that an option?

mr_belowski
01-09-2019, 05:50 PM
I'll have a look at upper case later. Caps lock is unlikely to work

mr_belowski
01-09-2019, 07:22 PM
ok, this should work in the release I'm just about to unleash. In {FREE_TEXT} blocks, any capital letters will automatically trigger the left-shift key to be held down while they're being pressed. And the '/' symbol will be interpreted correctly.

Please please please, if you're editing saved_command_macros.json file in your installation folder (C:\Program Files\CrewChiefv4\ or whatever it is) you *must* back it up before updating. If you're editing a copy of the file in Documents\CrewChiefV4\ then it'll all be fine :)

Scoops
01-10-2019, 03:15 PM
Thanks Mr B all sorted with this update :cool: