/// <summary> /// Enables keyboarding. This should be called during application startup. /// </summary> public static void Initialize(params IKeyboardRetrievingAdaptor[] adaptors) { // Note: arguably it is undesirable to install this as the public keyboard controller before we initialize it. // However, we have not in general attempted thread safety for the keyboarding code; it seems // highly unlikely that any but the UI thread wants to manipulate keyboards. Apart from other threads, nothing // has a chance to access this before we return. If initialization does not complete successfully, we clear the // global. try { if (_instance != null) Shutdown(); _instance = new KeyboardController(); Keyboard.Controller = _instance; if (adaptors.Length == 0) _instance.SetDefaultKeyboardAdaptors(); else _instance.SetKeyboardAdaptors(adaptors); } catch (Exception e) { Console.WriteLine("Got exception {0} initalizing keyboard controller", e.GetType()); Console.WriteLine(e.StackTrace); Logger.WriteEvent("Got exception {0} initalizing keyboard controller", e.GetType()); Logger.WriteEvent(e.StackTrace); if (Keyboard.Controller != null) Keyboard.Controller.Dispose(); Keyboard.Controller = null; throw; } }
/// <summary> /// Enables keyboarding. This should be called during application startup. /// </summary> public static void Initialize(params IKeyboardRetrievingAdaptor[] adaptors) { // Note: arguably it is undesirable to install this as the public keyboard controller before we initialize it. // However, we have not in general attempted thread safety for the keyboarding code; it seems // highly unlikely that any but the UI thread wants to manipulate keyboards. Apart from other threads, nothing // has a chance to access this before we return. If initialization does not complete successfully, we clear the // global. try { if (Instance != null) { Shutdown(); } Instance = new KeyboardController(); Keyboard.Controller = Instance; if (adaptors.Length == 0) { Instance.SetDefaultKeyboardAdaptors(); } else { Instance.SetKeyboardAdaptors(adaptors); } } catch (Exception e) { Console.WriteLine("Got exception {0} initializing keyboard controller", e.GetType()); Console.WriteLine(e.StackTrace); Logger.WriteEvent("Got exception {0} initializing keyboard controller", e.GetType()); Logger.WriteEvent(e.StackTrace); if (Keyboard.Controller != null) { Keyboard.Controller.Dispose(); } Keyboard.Controller = null; throw; } }