force_english_ime 0.0.4 copy "force_english_ime: ^0.0.4" to clipboard
force_english_ime: ^0.0.4 copied to clipboard

PlatformWindows

A Windows plugin for Flutter that forces English input mode by completely disabling IME. Prevents users from switching input methods via shortcuts like Shift or Ctrl+Space.

force_english_ime #

pub package license

中文文档

A Windows plugin for Flutter that forces English input mode by completely disabling IME. Prevents users from switching input methods via shortcuts like Shift or Ctrl+Space.

Features #

  • Complete IME Disable - Uses ImmAssociateContext to completely disable IME
  • Automatic State Management - Auto-save and restore IME state
  • Accurate Detection - Precise input mode detection using ImmGetConversionStatus
  • Real-time Monitoring - Listen to IME state changes via onImeStateChanged stream
  • Emergency Recovery - Use cancelForceEnglish() to re-enable IME when stuck
  • Zero Dependencies - Only uses Windows IMM API
  • Easy Integration - Simple API with Focus widget support

Platform Support #

Platform Support
Windows
macOS
Linux
Android
iOS

Installation #

Add to pubspec.yaml:

dependencies:
  force_english_ime: ^0.0.4

Then run:

flutter pub get

Quick Start #

Basic Usage #

import 'package:force_english_ime/force_english_ime.dart';

final _imePlugin = ForceEnglishIme();

// Check if English IME
bool isEnglish = await _imePlugin.isEnglishIme();

// Force English input
await _imePlugin.forceEnglishInput();

// Restore original IME
await _imePlugin.restoreOriginalIme();

// Emergency: re-enable IME with a fresh context (when restoreOriginalIme fails)
await _imePlugin.cancelForceEnglish();

Use with TextField #

class EmailInput extends StatefulWidget {
  @override
  State<EmailInput> createState() => _EmailInputState();
}

class _EmailInputState extends State<EmailInput> {
  final _imePlugin = ForceEnglishIme();
  final _controller = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Focus(
      onFocusChange: (hasFocus) {
        if (hasFocus) {
          _imePlugin.forceEnglishInput();
        } else {
          _imePlugin.restoreOriginalIme();
        }
      },
      child: TextField(
        controller: _controller,
        decoration: const InputDecoration(
          labelText: 'Email',
          hintText: 'example@email.com',
        ),
      ),
    );
  }
}

Listen to IME State Changes #

final ime = ForceEnglishIme();

ime.onImeStateChanged.listen((event) {
  switch (event['type']) {
    case 'conversionModeChanged':
      print('Alphanumeric: ${event['isAlphanumeric']}');
      break;
    case 'openStatusChanged':
      print('IME open: ${event['isOpen']}');
      break;
    case 'inputLanguageChanged':
      print('Language: ${event['languageTag']}');
      break;
  }
});

API Reference #

Methods #

Future<bool> isEnglishIme()

Check if current IME is in English mode.

Returns: true if in English mode, false otherwise.

Future<bool> forceEnglishInput()

Force English input by completely disabling IME.

Returns: true if successful, false otherwise.

Future<bool> restoreOriginalIme()

Restore the original IME state.

Returns: true if successful, false otherwise.

Future<bool> cancelForceEnglish()

Re-enable IME by creating a fresh IME context. Unlike restoreOriginalIme, this does not attempt to restore the previous state.

Returns: true if successful, false otherwise.

Streams #

Stream<Map<String, dynamic>> onImeStateChanged

A stream of real-time IME state change events.

Event types:

Type Description Data
conversionModeChanged Input mode toggled (English ↔ native) { isAlphanumeric: bool }
openStatusChanged IME opened or closed { isOpen: bool }
inputLanguageChanged System input language changed { languageId: int, languageTag: String }

Use Cases #

  • 📧 Email input
  • 👤 Username input
  • 🔗 URL input
  • 💻 Code editor
  • 🔑 API key input
  • And more...

How It Works #

This plugin uses Windows IMM (Input Method Manager) API:

  • ImmAssociateContext(hwnd, NULL) - Completely disables IME
  • ImmCreateContext() - Creates a fresh IME context for recovery
  • ImmGetConversionStatus() - Detects input mode
  • GetFocus() - Gets current focused control
  • SetWindowSubclass - Intercepts WM_IME_NOTIFY and WM_INPUTLANGCHANGE for real-time monitoring

When IME is disabled, users cannot switch input methods via any shortcuts (Shift, Ctrl+Space, etc.).

Examples #

Check out the example directory for a complete demo app.

Requirements #

  • Flutter SDK: >= 3.0.0
  • Dart SDK: >= 2.17.0
  • Windows 10 or higher recommended

License #

MIT License - see LICENSE file for details.

Contributing #

Issues and Pull Requests are welcome!

1
likes
160
points
34
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Windows plugin for Flutter that forces English input mode by completely disabling IME. Prevents users from switching input methods via shortcuts like Shift or Ctrl+Space.

Repository (GitHub)
View/report issues

Topics

#ime #windows #input-method #flutter-plugin #input-control

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on force_english_ime

Packages that implement force_english_ime