61 lines
1.4 KiB
C#
61 lines
1.4 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Security.Principal;
|
|
|
|
public class KeyboardHelper
|
|
{
|
|
public static void ShowSoftKeyboard()
|
|
{
|
|
if (!IsRunAsAdmin())
|
|
{
|
|
RestartAsAdmin();
|
|
return;
|
|
}
|
|
|
|
Process.Start(new ProcessStartInfo
|
|
{
|
|
FileName = "osk.exe",
|
|
UseShellExecute = true
|
|
});
|
|
}
|
|
|
|
public static void HideSoftKeyboard()
|
|
{
|
|
try
|
|
{
|
|
Process.Start("cmd.exe", "/C taskkill /IM osk.exe /F");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Error: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private static bool IsRunAsAdmin()
|
|
{
|
|
WindowsIdentity identity = WindowsIdentity.GetCurrent();
|
|
WindowsPrincipal principal = new WindowsPrincipal(identity);
|
|
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
|
}
|
|
|
|
private static void RestartAsAdmin()
|
|
{
|
|
ProcessStartInfo startInfo = new ProcessStartInfo();
|
|
startInfo.UseShellExecute = true;
|
|
startInfo.WorkingDirectory = Environment.CurrentDirectory;
|
|
startInfo.FileName = Process.GetCurrentProcess().MainModule.FileName;
|
|
startInfo.Verb = "runas";
|
|
|
|
try
|
|
{
|
|
Process.Start(startInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Error: " + ex.Message);
|
|
}
|
|
|
|
Environment.Exit(0);
|
|
}
|
|
}
|