Author Topic: Can I import keymap file to VA?  (Read 1749 times)

janjan

  • Newbie
  • *
  • Posts: 42
Can I import keymap file to VA?
« on: April 22, 2020, 05:35:01 AM »
I'm trying to improve my Falcon BMS profile but this can assist in any profile.

I want to generate a general keyMap profile and later use it in my topLevel profile so that if the key mapping changes or another user wishes to use the topLevel profile he should only create the keyMap profile.

Is there a way to import ,any kind of text format, to VA?
The text file should have the command name and key presses for it.
e.g
SimInteriorLight    - Shft - Alt - C   LIGHT: CONSOLES Knob (Flood) - Cycle

I only mean to import keyboard commands
« Last Edit: April 22, 2020, 06:33:58 AM by janjan »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Can I import keymap file to VA?
« Reply #1 on: April 22, 2020, 10:22:26 AM »
You can use the "Set a Text Value" action's "Value from file/URI" option to get all the text in a file

You'll then have to set up a command to parse that text (E.G. using the "{TXTSUBSTR:}" and "{TXTPOS:}" tokens in a loop).

Once you have separated the text into variables (E.G. a text variable named "SimInteriorLight", containing "[SHIFT][ALT]C"), you need use the "Refresh Variable Command Hotkeys" action to apply the changes.

After that, the hotkey(s) should trigger the command(s) that have a variable hotkey with that variable name assigned to them.


Search VoiceAttackHelp.pdf for "Use variable hotkey (Advanced)" and "Quick Input, Variable Keypress and Hotkey Key Indicators" for more information on variable hotkeys.

janjan

  • Newbie
  • *
  • Posts: 42
Re: Can I import keymap file to VA?
« Reply #2 on: April 22, 2020, 10:55:43 AM »
Thanks,
I'll create a test profile and try to use it.


janjan

  • Newbie
  • *
  • Posts: 42
Re: Can I import keymap file to VA?
« Reply #3 on: April 23, 2020, 04:33:38 AM »
I created the code which reads my file and generate the commands and it does work.
A few questions:

1. I currently added "," at the end of a command since i cannot get the {NEWLINE} to work.
How can I make this command work:
Code: [Select]
Set text [numOfLines] to '{TXTOCCURRENCES:lineEndMark:importedFile}'
Where  I set lineEndMark to '{NEWLINE}'

2. How cat I, as a user see the new command which were created during the new import process apart from showing them int the log.

3. Can/Should I save these hotkeys and if yes how?


Code: [Select]
Set text [importedFile] to [C:\Users\someUser\Saved Games\VoiceAttack\BMS\inputTest.txt] (Trim)
Set text [lineEndMark] to ','
DISABLED - Set text [lineEndMark] to '{NEWLINE}'
Set text [numOfLines] to '{TXTOCCURRENCES:lineEndMark:importedFile}'
Set integer [loopEnd] value to the converted value of {EXP: {TXTNUM:numOfLines}-1}
Set integer [lineStart] value to 0
Start Loop : Repeat From 0 to [{INT:loopEnd}]
    Set integer [lineEnd] value to the converted value of {EXP: {TXTPOS:lineEndMark:importedFile:lineStart} + 1}
    Set integer [lineLength] value to the converted value of {EXP: {INT:lineEnd}-{INT:lineStart}}
    Set text [txtLine] to '{TXTSUBSTR:importedFile:lineStart:{EXP: {INT:lineLength} - 1}}'
    Set integer [lineStart] value to the converted value of {EXP: {INT:lineEnd}+1}
    Now split the line to command & hotKey
    Set text [cmdSplit] to ':'
    Set integer [cmdSplitPos] value to the converted value of {TXTPOS:cmdSplit:txtLine:0}
    Set integer [hotKeyLength] value to the converted value of {EXP: {TXTLEN:txtLine} - {INT:cmdSplitPos}}
    Set text [cmdName] to '{TXTSUBSTR:txtLine:0:cmdSplitPos}'
    Set text [cmdHotKey] to '{TXTSUBSTR:txtLine:{EXP: {INT:cmdSplitPos} + 1}:hotKeyLength}'
    Set text [{TXT:cmdName}] to [cmdHotKey]
    Write [Orange] 'Line: {INT:i} => cmd:  {TXT:cmdName} : hotKey:  {TXT:cmdHotKey}' to log
End Loop
Refresh variable hotkeys
(this code can be minimized with EXP)

« Last Edit: April 23, 2020, 05:36:56 AM by janjan »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Can I import keymap file to VA?
« Reply #4 on: April 23, 2020, 09:52:49 AM »
1. I currently added "," at the end of a command since i cannot get the {NEWLINE} to work.
How can I make this command work:
Code: [Select]
Set text [numOfLines] to '{TXTOCCURRENCES:lineEndMark:importedFile}'
Where  I set lineEndMark to '{NEWLINE}'
If your file uses line endings that match Environment.Newline (which should be "\r\n" for Windows), that should already work.


2. How cat I, as a user see the new command which were created during the new import process apart from showing them int the log.
This process does not create new commands, it only applies changes to commands that have been previously set up to use a variable hotkey.

As the hotkeys are specified, presumably by the user, in the file you're importing from, I'm not sure what information you want to display.


3. Can/Should I save these hotkeys and if yes how?
You can save the values of the variables using the "Save value to profile" option.

To retrieve that data you will need to set each of those variables using the "Retrieve saved value" option, and use the "Refresh Variable Command Hotkeys" to enable the hotkeys.

janjan

  • Newbie
  • *
  • Posts: 42
Re: Can I import keymap file to VA?
« Reply #5 on: April 23, 2020, 10:31:27 AM »
Thanks for you reply.

The {NEWLINE} is still not working for me.
I use a simple txt file created with gvim on windows.
I've attached it.

I tried to set it to a variable, same thing i do for ":" as the manual says but that did not help either.


Regarding the information I want to display, after importing these commands is actually a list of the newly added commands.
I can create/modify the creation function to show them but i though there may be a way to show what hotkeys are stores in memory.


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Can I import keymap file to VA?
« Reply #6 on: April 23, 2020, 10:38:18 AM »
If your file uses line endings that match Environment.Newline (which should be "\r\n" for Windows), that should already work.
That file does not use the correct line endings; It only has "\n", which is the Unix style.

Either change the setting in gvim, or use notepad.


i though there may be a way to show what hotkeys are stores in memory.
You already know the variable names the hotkeys can be stored in, so you can check those, no?

There is no method for getting arbitrary lists of VoiceAttack variables, in any scope.

janjan

  • Newbie
  • *
  • Posts: 42
Re: Can I import keymap file to VA?
« Reply #7 on: April 23, 2020, 12:21:23 PM »
Thanks,
And now i have to skip 2 places ahead every time i increment my line counter since {NEWLINE} occupied 2 spaces, correct?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Can I import keymap file to VA?
« Reply #8 on: April 23, 2020, 12:27:07 PM »
Have you taken the time to test this for yourself?

janjan

  • Newbie
  • *
  • Posts: 42
Re: Can I import keymap file to VA?
« Reply #9 on: April 23, 2020, 12:35:46 PM »
Of course.
It took me some time to realize why it was not working and I concluded that the {NEWLINE} takes 2 characters.

janjan

  • Newbie
  • *
  • Posts: 42
Re: Can I import keymap file to VA?
« Reply #10 on: April 24, 2020, 03:00:15 AM »
According to the manual I can use the "Save value to profile" to save the variable value withing the profile.
I can then load the values for those variables. When I have many such variable I need to create a loop which goes through each value name and restore their value.
In my case this takes as long as reading the values from a file and creating them.
Is there a way to save the variable with the profile so that they will be available when I restart VA without going though each value and retrieve its value?
I'm trying to save the initial load time of the profile - define the variable once after reading them from a file - I completed this part, but I's rather not do this process very time the profile loads. This or retrieving the values.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Can I import keymap file to VA?
« Reply #11 on: April 24, 2020, 08:48:11 AM »
Values must be retrieved manually, just as it says in the documentation.