전자반자 체크하여 반자로 전환
using System;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
// IMM 관련 API 선언
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("imm32.dll")]
private static extern IntPtr ImmGetContext(IntPtr hWnd);
[DllImport("imm32.dll")]
private static extern bool ImmSetConversionStatus(IntPtr hIMC, uint fdwConversion, uint fdwSentence);
[DllImport("imm32.dll")]
private static extern bool ImmGetConversionStatus(IntPtr hIMC, out uint lpfdwConversion, out uint lpfdwSentence);
static void Main()
{
IntPtr hwnd = GetForegroundWindow(); // 현재 활성화된 윈도우 가져오기
uint processId;
uint threadId = GetWindowThreadProcessId(hwnd, out processId);
IntPtr hIMC = ImmGetContext(hwnd); // 해당 윈도우의 입력 컨텍스트 가져오기
if (hIMC != IntPtr.Zero)
{
uint conversionMode, sentenceMode;
if (ImmGetConversionStatus(hIMC, out conversionMode, out sentenceMode))
{
Console.WriteLine($"현재 입력기 상태: {conversionMode}");
{
Console.WriteLine("현재 입력기를 가져올 수 없습니다.");
}
}
}
// IME 변환 모드를 변경 (예: 전자 입력 모드 설정)
const uint IME_CMODE_FULLSHAPE = 0x0008; // 전자 모드
const uint IME_CMODE_HALFSHAPE = 0x0000; // 반자 모드
bool success = ImmSetConversionStatus(hIMC, IME_CMODE_FULLSHAPE, sentenceMode);
Console.WriteLine(success ? "IME 설정이 변경되었습니다!" : "IME 설정 변경 실패");
}
}
else