Author Topic: Script for changing keyboard layout language  (Read 7037 times)

woofer

  • Newbie
  • *
  • Posts: 18
    • Youtube channel
Script for changing keyboard layout language
« on: February 27, 2017, 04:31:23 PM »
Hi!

I just found out that VoiceAttack uses virtual keycodes. If I have understood it all correctly, then that means that the physical key for certain keycodes aren't the same on some keys between keyboard layouts.

So when I'm creating a profile on a swedish keyboard that uses the key next to top row 1-key, I would get the keycode 220. That key is sometimes called the "tilde key".

If someone was using my profile with a US keyboard Layout, they would instead get keycode 192 by pressing the same physical key and the command would not work as intended since 220 is somewhere else on their keyboard. Arma - the game I'm designing for apparently uses DIK KeyCodes and are only concerned with the physical key location.

My problem is this:
Alpha-Kilo and I are trying to create one single, simple and accessible profile that can be used with the standard keybindings in Arma. We don't want to create and maintain separate profiles for each keyboard layout with different keys that are used.

I read that pressing the key as "standard" instead of DirectX might resolve the issue, but that has been proven to be unreliable in the history of Arma/VoiceAttack.

I thought that the most robust way to solve this would be to create a function where the user specifies if and what other than english keyboard they are using and it would be called whenever any of the offending keys were used. I wrote a mock-up for what the function could look like below.

I thought that the most robust way to solve this would be to create a function that writes the correct keycodes into variables to be used as variable keypresses. The user would then have to specify if they are using any other language keyboard layout than US english in a regular voice command the first time they use the profile.


My questions are these:
Am I overthinking this or is there something I missed? Is the variable keypress method a good way to go? I have a very large profile to edit if I do it like I planned, so I was hoping for some kind of input before I start.

Code: [Select]
// This function is called to set the correct keys corresponding to what keyboard layout is used in Arma.
// It is useful for an english voice profile that is being run with different keyboard layouts since
// VoiceAttack is using virtual keycodes with DirectX input.
// There will be a VA command to set and save the _keyboardLayout value to profile.

// 1 = US English and UK english keyboard (default)
// 2 = Swedish keyboard


If _keyboardLayout = NULL
  {
    _keyboardLayout = 1
  }
end


If _keyboardLayout = 1
  {
    // Set physical tilde key to english virtual keycode
    _keycodeSelectAllUnits = [192] (and save to profile)
    // ... add additional required offending keys
  }
end

If _keyboardLayout = 2
  {
    // Set physical tilde key to swedish virtual keycode
    _keycodeSelectAllUnits = [220] (and save to profile)
    // ... add additional required offending keys
  }
end
« Last Edit: February 27, 2017, 04:45:28 PM by woofer »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Script for changing keyboard layout language
« Reply #1 on: February 27, 2017, 05:33:19 PM »
I read that pressing the key as "standard" instead of DirectX might resolve the issue, but that has been proven to be unreliable in the history of Arma/VoiceAttack.
If you still have that option available, you'll probably want to upgrade to a newer version of VoiceAttack. It's no longer necessary nor possible to manually set the method used.

I thought that the most robust way to solve this would be to create a function that writes the correct keycodes into variables to be used as variable keypresses. The user would then have to specify if they are using any other language keyboard layout than US english in a regular voice command the first time they use the profile.
You don't have to put the burden on the user, as you could programatically retrieve the current keyboard layout:
Code: [Select]
public class VAInline
{
public void main()
{

VA.SetText("KeyboardLayout", System.Windows.Forms.InputLanguage.CurrentInputLanguage.LayoutName);
}
}
Example code found here.


Though, ideally, you'd want to get the keycodes from the "user.Arma3Profile" that the game itself generates, assuming those keycodes are correct for the user's keyboard layout.

woofer

  • Newbie
  • *
  • Posts: 18
    • Youtube channel
Re: Script for changing keyboard layout language
« Reply #2 on: February 28, 2017, 01:44:22 AM »
Thanks for the reply! I am sitting on a finished profile, but ran into this keyboard layout problem just the other day.

Quote
If you still have that option available, you'll probably want to upgrade to a newer version of VoiceAttack. It's no longer necessary nor possible to manually set the method used.

Oh, I had missed that there no longer is an option for input method. Good, one less thing to consider.

Quote
You don't have to put the burden on the user, as you could programatically retrieve the current keyboard layout:

This looks really neat. However, I'm a complete and utter beginner at this stuff with only some surface level coding to lean on.
Does this only work if put into a plugin? I want build the profile through plugin sometime in the future, but it's a bit above my head at the moment.
From reading the VoiceAttack help, I'm guessing I can't run this code within a command and something like a Quick Input for example?

What I have done for my profile is to create commands that act like functions. I name them something like "F_feedbackMode", disable the voice activation for them and then execute that command in other commands as needed. I wasn't particularily clear about what I meant with "functions".

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Script for changing keyboard layout language
« Reply #3 on: February 28, 2017, 05:03:16 AM »
Does this only work if put into a plugin?
It's intended to be used with the "Inline Function - C# Code" action, found under Other>Advanced>Execute an Inline Function>C# Code.

You paste that in the editor and overwrite anything already in the example, and when you run the command, the text value "KeyboardLayout" should be set to the name of the default keyboard layout on your machine.
What you do with that text value afterwards is up to you.

woofer

  • Newbie
  • *
  • Posts: 18
    • Youtube channel
Re: Script for changing keyboard layout language
« Reply #4 on: February 28, 2017, 08:15:32 AM »
Quote
It's intended to be used with the "Inline Function - C# Code" action, found under Other>Advanced>Execute an Inline Function>C# Code.

That is absolutely awesome! Just perfect for guys like me with surface level programming skills. Can't wait to really dig into it.

I didn't have the option because I was on release version 1.6.1.0 instead of the beta.

Thanks for the great help as always pfeil!

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Script for changing keyboard layout language
« Reply #5 on: February 28, 2017, 09:00:48 AM »
What you guys probably need to know is that VA uses the system's keyboard layout by default.  The layout selection from the options screen was added some time ago for pack creators and is probably almost NEVER used.  I shouldn't have added it, but it seemed helpful at the time.  Long story short, the effort you would put into that would only be helpful to like one person out there (maybe).

woofer

  • Newbie
  • *
  • Posts: 18
    • Youtube channel
Re: Script for changing keyboard layout language
« Reply #6 on: February 28, 2017, 09:38:57 AM »
Alright, thanks for the heads up.

To be honest, there are probably not more than two keys that are a constant problem from what I am hearing of users of my older profile. It's a big enough obstacle for new users that I want to make an effort to see what can be done.

Anyway, I'm very grateful for VA and the help you guys provide. Not to mention one of the best help documentations out there.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Script for changing keyboard layout language
« Reply #7 on: February 28, 2017, 09:39:48 AM »
VA uses the system's keyboard layout by default.  The layout selection from the options screen was added some time ago for pack creators and is probably almost NEVER used.  I shouldn't have added it, but it seemed helpful at the time.
If I understand correctly, that option affects the visual representation of the keycodes in dialogs, not the way keycodes are processed.
Quote from: VoiceAttackHelp.pdf
If you are in the
US, '3 #' is displayed. If you are in the UK, '3 £' is displayed.
E.G. if I map the key above "Tab", left of "1", to a command in VoiceAttack, and send that profile to someone with a different layout, there is not guarantee that the physical location of the key that triggers the command will be the same.

The OP's intent is to automatically compensate for this difference across different layouts, to match the physical locations of the original layout, even though they represent different characters.


What could be an alternative solution, should it be implemented, is this feature request, which was made with exactly this problem in mind.

That said, I'm still of the opinion that parsing the game's settings file is the right way to go, so you can account for keys that have been rebound away from their original locations while removing the requirement for the end user to press or otherwise manually assign keys.


Gary, as an aside, if you do keep it, the tooltip for the "Keyboard Display Layout :" label is a duplicate of the speech engine one: "This is the speech engine that VoiceAttack will use (you will rarely need to change this)".

woofer

  • Newbie
  • *
  • Posts: 18
    • Youtube channel
Re: Script for changing keyboard layout language
« Reply #8 on: February 28, 2017, 10:42:47 AM »
Quote
That said, I'm still of the opinion that parsing the game's settings file is the right way to go, so you can account for keys that have been rebound away from their original locations while removing the requirement for the end user to press or otherwise manually assign keys.

I agree, this is definitely the way to go. I (also) want to get some kind of mod going and better connect VA to the actual Arma game trough plugin, but that is a bit into the future since I'm learning as I go.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Script for changing keyboard layout language
« Reply #9 on: February 28, 2017, 11:45:38 AM »
Quote
Gary, as an aside, if you do keep it, the tooltip for the "Keyboard Display Layout :" label is a duplicate of the speech engine one: "This is the speech engine that VoiceAttack will use (you will rarely need to change this)".

Yay...copy/paste.   Ugh... its on the label o_O

That would be a very old one.