Skip to content

Commit

Permalink
Additional IME handling
Browse files Browse the repository at this point in the history
* Handle IME for all input expect Steam Guard 2FA toggle setting.
* Add Key Up events for send and post message calls #98
  • Loading branch information
rex706 committed Apr 8, 2020
1 parent 55fcf35 commit ee6d2da
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
15 changes: 14 additions & 1 deletion SAM/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,14 @@ private void TypeCredentials(int index, int tryCount)
Thread.Sleep(settings.User.SleepTime);
Utils.SetForegroundWindow(steamLoginWindow.RawPtr);
Thread.Sleep(100);


// Enable Caps-Lock, to prevent IME problems.
bool capsLockEnabled = System.Windows.Forms.Control.IsKeyLocked(System.Windows.Forms.Keys.CapsLock);
if (settings.User.HandleMicrosoftIME && !settings.User.IME2FAOnly && !capsLockEnabled)
{
Utils.SendCapsLockGlobally();
}

foreach (char c in decryptedAccounts[index].Name.ToCharArray())
{
Utils.SetForegroundWindow(steamLoginWindow.RawPtr);
Expand Down Expand Up @@ -1398,6 +1405,12 @@ private void TypeCredentials(int index, int tryCount)
Thread.Sleep(100);
Utils.SendEnter(steamLoginWindow.RawPtr, settings.User.VirtualInputMethod);

// Restore CapsLock back if CapsLock is off before we start typing.
if (settings.User.HandleMicrosoftIME && !settings.User.IME2FAOnly && !capsLockEnabled)
{
Utils.SendCapsLockGlobally();
}

int waitCount = 0;

// Only handle 2FA if shared secret was entered.
Expand Down
2 changes: 2 additions & 0 deletions SAM/SAMSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SAMSettings
public const string SELECTED_ACCOUNT_INDEX = "SelectedAccountIndex";
public const string INPUT_METHOD = "InputMethod";
public const string HANDLE_IME = "HandleIME";
public const string IME_2FA_ONLY = "IME_2FA_ONLY";

public const string THEME = "Theme";
public const string ACCENT = "Accent";
Expand Down Expand Up @@ -109,6 +110,7 @@ class SAMSettings
{ SELECTED_ACCOUNT_INDEX, SECTION_AUTOLOG },
{ INPUT_METHOD, SECTION_AUTOLOG },
{ HANDLE_IME, SECTION_AUTOLOG },
{ IME_2FA_ONLY, SECTION_AUTOLOG },

{ THEME, SECTION_CUSTOMIZE },
{ ACCENT, SECTION_CUSTOMIZE },
Expand Down
3 changes: 2 additions & 1 deletion SAM/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
<TextBlock x:Name="selectedAccountLabel" Text="" HorizontalAlignment="Left" Margin="121,66,0,0" VerticalAlignment="Top"/>
<TextBlock Text="Auto accounts only trigger if Steam is closed" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" TextDecorations="Underline"/>
<TextBlock Text="Automatic Input Method:" HorizontalAlignment="Center" Margin="17,122,187,0" VerticalAlignment="Top"/>
<CheckBox x:Name="HandleImeCheckBox" Content="Handle Microsoft IME" HorizontalAlignment="Left" Margin="17,153,0,0" VerticalAlignment="Top" ToolTip="Toggle Caps-Lock when automatically entering characters to handle IME for international keyboard settings."/>
<CheckBox x:Name="HandleImeCheckBox" Content="Handle Microsoft IME" HorizontalAlignment="Left" Margin="17,153,0,0" VerticalAlignment="Top" ToolTip="Toggle Caps-Lock when automatically entering characters to handle IME for international keyboard settings." Checked="HandleImeCheckBox_Checked" Unchecked="HandleImeCheckBox_Unchecked"/>
<ComboBox x:Name="InputMethodSelectBox" HorizontalAlignment="Left" Margin="159,118,0,0" VerticalAlignment="Top" Width="154"/>
<Rectangle HorizontalAlignment="Left" Height="1" Margin="10,102,0,0" VerticalAlignment="Top" Width="318" Fill="{DynamicResource xctkForegoundBrush}"/>
<CheckBox x:Name="SteamGuardOnlyCheckBox" Content="2FA Only" HorizontalAlignment="Left" Margin="184,153,0,0" VerticalAlignment="Top" ToolTip="Only toggle Caps-Lock for the Steam Guard 2FA window." IsEnabled="False"/>
</Grid>
</TabItem>
<TabItem Header="Customize" mah:ControlsHelper.HeaderFontSize="{DynamicResource TabItemFontSize}">
Expand Down
14 changes: 14 additions & 0 deletions SAM/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private void SettingsWindow_Loaded(object sender, RoutedEventArgs e)
}
InputMethodSelectBox.SelectedItem = (VirtualInputMethod)Enum.Parse(typeof(VirtualInputMethod), settings.File.Read(SAMSettings.INPUT_METHOD, SAMSettings.SECTION_AUTOLOG));
HandleImeCheckBox.IsChecked = Convert.ToBoolean(settings.File.Read(SAMSettings.HANDLE_IME, SAMSettings.SECTION_AUTOLOG));
SteamGuardOnlyCheckBox.IsChecked = Convert.ToBoolean(settings.File.Read(SAMSettings.IME_2FA_ONLY, SAMSettings.SECTION_AUTOLOG));

// Customize
ThemeSelectBox.Text = settings.File.Read(SAMSettings.THEME, SAMSettings.SECTION_CUSTOMIZE);
Expand Down Expand Up @@ -247,6 +248,7 @@ private void SaveSettings(string apr)
settings.File.Write(SAMSettings.LOGIN_RECENT_ACCOUNT, selectedAccountCheckBox.IsChecked.ToString(), SAMSettings.SECTION_AUTOLOG);
settings.File.Write(SAMSettings.INPUT_METHOD, InputMethodSelectBox.SelectedItem.ToString(), SAMSettings.SECTION_AUTOLOG);
settings.File.Write(SAMSettings.HANDLE_IME, HandleImeCheckBox.IsChecked.ToString(), SAMSettings.SECTION_AUTOLOG);
settings.File.Write(SAMSettings.IME_2FA_ONLY, SteamGuardOnlyCheckBox.IsChecked.ToString(), SAMSettings.SECTION_AUTOLOG);

// Steam
settings.File.Write(SAMSettings.STEAM_PATH, SteamPathTextBox.Text, SAMSettings.SECTION_STEAM);
Expand Down Expand Up @@ -411,6 +413,7 @@ private void DefaultButton_Click(object sender, RoutedEventArgs e)
selectedAccountCheckBox.IsChecked = settings.Default.LoginSelectedAccount;
InputMethodSelectBox.SelectedItem = settings.Default.VirtualInputMethod;
HandleImeCheckBox.IsChecked = settings.Default.HandleMicrosoftIME;
SteamGuardOnlyCheckBox.IsChecked = settings.Default.IME2FAOnly;

SteamPathTextBox.Text = Utils.CheckSteamPath();
ApiKeyTextBox.Text = settings.Default.ApiKey;
Expand Down Expand Up @@ -486,5 +489,16 @@ private void CustomParamsHelpButton_Click(object sender, RoutedEventArgs e)
{
Process.Start("https://developer.valvesoftware.com/wiki/Command_Line_Options#Steam_.28Windows.29");
}

private void HandleImeCheckBox_Checked(object sender, RoutedEventArgs e)
{
SteamGuardOnlyCheckBox.IsEnabled = true;
}

private void HandleImeCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
SteamGuardOnlyCheckBox.IsEnabled = false;
SteamGuardOnlyCheckBox.IsChecked = false;
}
}
}
2 changes: 2 additions & 0 deletions SAM/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class UserSettings
public int SelectedAccountIndex { get { return (int)KeyValuePairs[SAMSettings.SELECTED_ACCOUNT_INDEX]; } set { KeyValuePairs[SAMSettings.SELECTED_ACCOUNT_INDEX] = value; } }
public VirtualInputMethod VirtualInputMethod { get { return (VirtualInputMethod)KeyValuePairs[SAMSettings.INPUT_METHOD]; } set { KeyValuePairs[SAMSettings.INPUT_METHOD] = value; } }
public bool HandleMicrosoftIME { get { return (bool)KeyValuePairs[SAMSettings.HANDLE_IME]; } set { KeyValuePairs[SAMSettings.HANDLE_IME] = value; } }
public bool IME2FAOnly { get { return (bool)KeyValuePairs[SAMSettings.IME_2FA_ONLY]; } set { KeyValuePairs[SAMSettings.IME_2FA_ONLY] = value; } }

#endregion

Expand Down Expand Up @@ -134,6 +135,7 @@ public DateTime? LastAutoReload {
{ SAMSettings.SELECTED_ACCOUNT_INDEX, -1 },
{ SAMSettings.INPUT_METHOD, VirtualInputMethod.SendMessage },
{ SAMSettings.HANDLE_IME, false },
{ SAMSettings.IME_2FA_ONLY, false },

{ SAMSettings.STEAM_PATH, string.Empty },
{ SAMSettings.STEAM_API_KEY, string.Empty },
Expand Down
4 changes: 4 additions & 0 deletions SAM/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,12 @@ public static void SendEnter(IntPtr hwnd, VirtualInputMethod inputMethod)
{
case VirtualInputMethod.SendMessage:
SendMessage(hwnd, WM_KEYDOWN, VK_RETURN, IntPtr.Zero);
SendMessage(hwnd, WM_KEYUP, VK_RETURN, IntPtr.Zero);
break;

case VirtualInputMethod.PostMessage:
PostMessage(hwnd, WM_KEYDOWN, (IntPtr)VK_RETURN, IntPtr.Zero);
PostMessage(hwnd, WM_KEYUP, (IntPtr)VK_RETURN, IntPtr.Zero);
break;

case VirtualInputMethod.SendWait:
Expand All @@ -830,10 +832,12 @@ public static void SendTab(IntPtr hwnd, VirtualInputMethod inputMethod)
{
case VirtualInputMethod.SendMessage:
SendMessage(hwnd, WM_KEYDOWN, VK_TAB, IntPtr.Zero);
SendMessage(hwnd, WM_KEYUP, VK_TAB, IntPtr.Zero);
break;

case VirtualInputMethod.PostMessage:
PostMessage(hwnd, WM_KEYDOWN, (IntPtr)VK_TAB, IntPtr.Zero);
PostMessage(hwnd, WM_KEYUP, (IntPtr)VK_TAB, IntPtr.Zero);
break;

case VirtualInputMethod.SendWait:
Expand Down

0 comments on commit ee6d2da

Please sign in to comment.