Skip to content

Commit 2e57b41

Browse files
committed
Changelog:
V1.1 - improve Keyboard mapping and key id - added Keyboard layout identification and labelling of the image - added mean to provide keyboard labels as JSON files - added some keyboard label files - fixes some found along the way
1 parent 5669a9a commit 2e57b41

File tree

277 files changed

+74255
-825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+74255
-825
lines changed

.vs/MSFS2020Ctrls/v16/.suo

92 KB
Binary file not shown.

AApp/AppSettings.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public Point FormLocation
5959

6060
[UserScopedSetting( )]
6161
[DefaultSettingValue( "en-US" )] // just a default
62-
public string MyLanguageChoice
63-
{
62+
public string MyLanguageChoice {
6463
get { return (string)this["MyLanguageChoice"]; }
6564
set { this["MyLanguageChoice"] = value; }
6665
}

Doc/MSFS2020Ctrls_QGuide V1.1.pdf

2.05 MB
Binary file not shown.

Doc/MSFS2020Ctrls_QGuide V1.x.pub

1.5 KB
Binary file not shown.

FrmMain.Designer.cs

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FrmMain.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ public FrmMain( )
6363
//lblTitle.Text += " - V " + version.Substring( 0, version.IndexOf( ".", version.IndexOf( "." ) + 1 ) ); // PRODUCTION
6464
this.Text += " - V " + version + " beta"; // BETA
6565

66+
// set the one from the kbd driver if found
67+
bool exists = Support.KbdLayout.Instance.KbdLayoutExists(Support.InputTransform.KbdLayoutID);
68+
Support.KbdLayout.Instance.SetKbdLayout( Support.InputTransform.KbdLayoutID ); // gets the default one if not found
69+
if ( exists )
70+
lblLang.Text = Support.InputTransform.LocaleString;
71+
else
72+
lblLang.Text = "("+Support.InputTransform.LocaleString+")";
73+
6674
btLoad.Focus( );
6775

6876
}
@@ -142,5 +150,20 @@ private void btPrint_Click( object sender, EventArgs e )
142150
PRINT = null;
143151
}
144152

153+
private void button1_Click( object sender, EventArgs e )
154+
{
155+
Support.KeyboardCls.MyLayoutName( );
156+
}
157+
158+
private void button1_Click_1( object sender, EventArgs e )
159+
{
160+
var kle = new Support.KLE_File();
161+
var x = new Support.KbdLayoutFile();
162+
x.MapKLIDs = new List<string>( ) { "00000411" };
163+
x.MapDescription = "Keyboard Layout for ja";
164+
x.MapComment = "Japanese Layout";
165+
x.MapKeys= kle.GetKeyLabels( "KBDJPN.json" );
166+
x.ToJson( "ja.json" );
167+
}
145168
}
146169
}

Layout/DeviceFile.cs

Lines changed: 87 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class DeviceFile
5353
public List<string> SupportedPidVid {
5454
get {
5555
List<string> ret = new List<string>();
56-
foreach( var id in InputDevices ) {
56+
foreach ( var id in InputDevices ) {
5757
ret.AddRange( id.DevicePIDVID );
5858
}
5959
return ret;
@@ -63,13 +63,24 @@ public List<string> SupportedPidVid {
6363
/// <summary>
6464
/// Create all possible ShapeItems for this Mapping File
6565
/// </summary>
66-
public void CreateShapes()
66+
public void CreateShapes( )
6767
{
6868
for ( int i = 0; i < InputDevices.Count; i++ ) {
6969
InputDevices[i].CreateShapes( );
7070
}
7171
}
7272

73+
/// <summary>
74+
/// Create all possible KeyLabels when the controls requires it
75+
/// </summary>
76+
/// <param name="dList">A Display List</param>
77+
public void LoadKeyLabels( DisplayList dList )
78+
{
79+
for ( int i = 0; i < InputDevices.Count; i++ ) {
80+
InputDevices[i].LoadKeyLabels( dList );
81+
}
82+
}
83+
7384
/// <summary>
7485
/// Find a Control entry with the given product guid and input command
7586
/// </summary>
@@ -101,7 +112,7 @@ public Control FindItem( string pidVid, string input, bool firstInstance )
101112
/// Get all devices with Name (only first GUID is returned)
102113
/// </summary>
103114
/// <returns></returns>
104-
public List<Device.DeviceDescriptor> Devices()
115+
public List<Device.DeviceDescriptor> Devices( )
105116
{
106117
var ret = new List<Device.DeviceDescriptor>( );
107118
for ( int i = 0; i < InputDevices.Count; i++ ) {
@@ -127,21 +138,26 @@ class Device
127138
[DataMember( Name = "DeviceName", IsRequired = true )]
128139
public string DeviceName { get; set; } // The device name
129140

130-
[DataMember(Name = "DeviceProdGuid", IsRequired = true )]
141+
[DataMember( Name = "DeviceProdGuid", IsRequired = true )]
131142
private List<string> DeviceProdGuid_ { get; set; } = new List<string>( ); // The device product GUIDs as read by DirectInput
132143

133-
[DataMember(Name = "Controls" )]
144+
[DataMember( Name = "Controls" )]
134145
public List<Control> Controls { get; set; } = new List<Control>( );// The list of Controls supported (see below)
135146

136147
// non Json
137148

149+
public bool IsInputType_Joystick => InputTypeLetter == "J";
150+
public bool IsInputType_Gamepad => InputTypeLetter == "G";
151+
public bool IsInputType_Mouse => InputTypeLetter == "M";
152+
public bool IsInputType_Kbd => InputTypeLetter == "K";
153+
public bool IsInputType_Kbd_Keys => InputTypeLetter == "X";
154+
138155

139156
private Font m_deviceFont = null;
140157
/// <summary>
141158
/// Get the base font for this device
142159
/// </summary>
143-
public Font DeviceFont
144-
{
160+
public Font DeviceFont {
145161
get {
146162
if ( !string.IsNullOrEmpty( FontFamily ) ) {
147163
return m_deviceFont;
@@ -158,23 +174,21 @@ public class DeviceDescriptor
158174
{
159175
public string DevGuid { get; set; } = "";
160176
public string DevName { get; set; } = "";
161-
public override string ToString()
177+
public override string ToString( )
162178
{
163179
return DevName;
164180
}
165181
}
166182

167-
public DeviceDescriptor DevDescriptor
168-
{
183+
public DeviceDescriptor DevDescriptor {
169184
get {
170-
return new DeviceDescriptor( ) { DevGuid = DeviceProdGuid_[0].ToLowerInvariant(), DevName = DeviceName };
185+
return new DeviceDescriptor( ) { DevGuid = DeviceProdGuid_[0].ToLowerInvariant( ), DevName = DeviceName };
171186
}
172187
}
173188

174189

175190
public string InputTypeLetter { get => InputType.Substring( 0, 1 ); }
176-
public int InputTypeNumber
177-
{
191+
public int InputTypeNumber {
178192
get {
179193
if ( InputType.Length > 1 ) {
180194
if ( int.TryParse( InputType.Substring( 1 ), out int num ) ) {
@@ -188,8 +202,7 @@ public int InputTypeNumber
188202
/// <summary>
189203
/// returns the PID VID part of the GUID (seems how this is composed in Win)
190204
/// </summary>
191-
public List<string> DevicePIDVID
192-
{
205+
public List<string> DevicePIDVID {
193206
get {
194207
var ret = new List<string>( );
195208
foreach ( string s in DeviceProdGuid_ ) {
@@ -207,7 +220,7 @@ public List<string> DevicePIDVID
207220
private int m_kbdItemTracker = 0;
208221
/// <summary>
209222
/// Find a Control entry with the given input command
210-
/// For Keyboards there is not an entry for every possible key - so return just the next one
223+
/// For Keyboards with drawn Keys there is not an entry for every possible key - so return just the next one
211224
/// </summary>
212225
/// <param name="input">the Item (device property)</param>
213226
/// <returns>The found Control or Null</returns>
@@ -219,8 +232,8 @@ public Control FindItem( string input )
219232
return Controls[i];
220233
}
221234
}
222-
// if not - and Keyboard - assign a new one and tag it
223-
if ( this.InputTypeLetter == "X" ) {
235+
// if not - and Keyboard with drawn Keys - assign a new one and tag it
236+
if ( this.IsInputType_Kbd_Keys ) {
224237
if ( Controls.Count > m_kbdItemTracker ) {
225238
int item = m_kbdItemTracker++;
226239
Controls[item].Input = input; // mark to reuse
@@ -234,15 +247,25 @@ public Control FindItem( string input )
234247
/// <summary>
235248
/// Create all possible ShapeItems for this Device
236249
/// </summary>
237-
public void CreateShapes()
250+
public void CreateShapes( )
238251
{
239252
m_kbdItemTracker = 0; // reset
240253
if ( m_deviceFont != null ) m_deviceFont.Dispose( );
241254
if ( !string.IsNullOrEmpty( FontFamily ) ) {
242255
m_deviceFont = new Font( FontFamily, MapProps.FontSize ); // create actual Font here
243256
}
244257
for ( int i = 0; i < Controls.Count; i++ ) {
245-
Controls[i].CreateShapes( DeviceFont, this.InputTypeLetter == "X" ); // symbols only for X type maps (keyboard with Symbols)
258+
Controls[i].CreateShapes( DeviceFont, this.IsInputType_Kbd_Keys ); // symbols only for X type maps (keyboard with Symbols)
259+
}
260+
}
261+
/// <summary>
262+
/// Create all possible KeyLabels when the control requires it
263+
/// </summary>
264+
/// <param name="dList"></param>
265+
public void LoadKeyLabels( DisplayList dList )
266+
{
267+
for ( int i = 0; i < Controls.Count; i++ ) {
268+
Controls[i].LoadKeyLabels( dList, this.IsInputType_Kbd_Keys ); // symbols only for X type maps (keyboard with Symbols)
246269
}
247270
}
248271

@@ -258,7 +281,7 @@ class Control
258281
public string Input { get; set; } = ""; // buttonN, hatN_up,_right,_down,_left, [rot]xyz, sliderN (CryInput notification)
259282

260283
[DataMember( Name = "Type" )]
261-
public string Type { get; set; } = ""; // "" or Analog or Digital
284+
public string Type { get; set; } = ""; // "" or Analog or Digital or Key
262285

263286
[DataMember( Name = "X", IsRequired = true )]
264287
public int X { get; set; } = 0; // X label pos (left=0)
@@ -293,6 +316,8 @@ class Control
293316
/// </summary>
294317
public void CreateShapes( Font deviceFontRef, bool useSymbol )
295318
{
319+
// define the number of Actionlabels to fit into the Control rectangle
320+
296321
// this is a bit messy...
297322
// have to allocate a number of Rectangles to draw into but the layout rects are very different in size..
298323
this.ShapeItems = new Queue<ShapeItem>( ); // get rid of previous ones
@@ -312,22 +337,40 @@ public void CreateShapes( Font deviceFontRef, bool useSymbol )
312337
}
313338
baseHeight = (int)Math.Floor( (double)Height / nLines ); // fill rectangle
314339

340+
// create as many shapes to hold action labels for this control
315341
bool symbol = useSymbol;
342+
// create one to draw the whole key
343+
if ( this.Type == "Key" && useSymbol ) {
344+
// Type Keyboard with keys drawn
345+
var sh = new ShapeKey {
346+
X = this.X,
347+
Y = this.Y,
348+
Width = this.Width,
349+
Height = this.Height/2,
350+
IsSymbolShape = true,
351+
TextFontRef = MapProps.KbdSymbolFont,
352+
};
353+
ShapeItems.Enqueue( sh ); // will only be drawn when used
354+
}
355+
316356
for ( int l = 0; l < nLines; l++ ) {
317357
for ( int c = 0; c < nCols; c++ ) {
318-
if ( this.Type == "Key" ) {
358+
359+
if ( this.Type == "KeyS" ) {
360+
// Type Keyboard with keys drawn
319361
var sh = new ShapeKey {
320362
X = X + c * baseWidth,
321363
Y = Y + l * baseHeight,
322364
Width = baseWidth,
323365
Height = baseHeight,
324-
IsSymbolShape = symbol,
366+
IsSymbolShape = false,
325367
TextFontRef = deviceFontRef
326368
};
327369
symbol = false; // only once
328370
ShapeItems.Enqueue( sh );
329371
}
330372
else {
373+
// other types - create labels only
331374
var sh = new ShapeItem {
332375
X = X + c * baseWidth,
333376
Y = Y + l * baseHeight,
@@ -341,6 +384,27 @@ public void CreateShapes( Font deviceFontRef, bool useSymbol )
341384
}
342385
}
343386

387+
/// <summary>
388+
/// Load KeyLabels if required by the control and mode (not if using symbols though)
389+
/// </summary>
390+
/// <param name="dList">A display list to add them</param>
391+
/// <param name="useSymbol">Wether or not usin Key Symbols rather than a drawn map</param>
392+
public void LoadKeyLabels( DisplayList dList, bool useSymbol )
393+
{
394+
if ( this.Type == "Key" && !useSymbol ) {
395+
// Type Keyboard with keys drawn
396+
var sh = new ShapeKey {
397+
X = this.X,
398+
Y = this.Y,
399+
Width = this.Width,
400+
Height = this.Height/2,
401+
IsLabelShape = true,
402+
DispText="DUMMY",
403+
SCGameKey = this.Input,
404+
};
405+
dList.Add( sh );
406+
}
344407

408+
}
345409
}
346410
}

Layout/FormLayout.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,26 +347,30 @@ private void Populate( )
347347
return;
348348
}
349349

350-
( cbxLayouts.SelectedItem as DeviceLayout ).DeviceController.CreateShapes( );
350+
var devController=( cbxLayouts.SelectedItem as DeviceLayout ).DeviceController;
351+
devController.CreateShapes( );
352+
devController.LoadKeyLabels( m_displayList );
351353
foreach ( var actItem in ActionList ) {
352354
// matches the selected device
353355
if ( MatchCriteria( actItem ) ) {
354356
bool firstInstance = ActionList.IsFirstInstance( actItem.DevicePidVid, actItem.InputTypeNumber );
355-
var ctrl = ( cbxLayouts.SelectedItem as DeviceLayout ).DeviceController.FindItem( actItem.DevicePidVid, actItem.MainControl, firstInstance );
357+
var ctrl = devController.FindItem( actItem.DevicePidVid, actItem.MainControl, firstInstance );
356358
if ( ctrl == null && actItem.InputTypeLetter == "J" ) {
357359
// for joysticks try the generic one
358-
ctrl = ( cbxLayouts.SelectedItem as DeviceLayout ).DeviceController.FindItem( "20002000", actItem.MainControl, firstInstance );
360+
ctrl = devController.FindItem( "20002000", actItem.MainControl, firstInstance );
359361
}
360362
if ( ctrl != null ) {
361363
if ( ctrl.ShapeItems.Count > 0 ) {
362364
var shape = ctrl.ShapeItems.Dequeue( );
365+
if (shape is ShapeKey ) {
366+
( shape as ShapeKey ).SCGameKey = actItem.MainControl; // content
367+
shape.DispText = "DUMMY"; // else it is ignored.. TODO make this better...
368+
m_displayList.Add( shape );
369+
shape = ctrl.ShapeItems.Dequeue( ); // pull one more if we got a non text shape
370+
}
363371
shape.DispText = actItem.ModdedDispText;
364372
shape.TextColor = MapProps.MapForeColor( actItem.ActionMap );
365373
shape.BackColor = MapProps.MapBackColor( actItem.ActionMap );
366-
if ( shape is ShapeKey ) {
367-
// kbd map
368-
( shape as ShapeKey ).SCGameKey = actItem.MainControl;
369-
}
370374
m_displayList.Add( shape );
371375
}
372376
else {

0 commit comments

Comments
 (0)