How to intercept/catch the event of OSK.exe(On-screen Keyboard) when displayed?

fazil k 11 Reputation points
2022-07-19T16:17:14.027+00:00

I need to intercept/catch the OSK.exe event when it launched or how to call an custom_osk before default one launches without editing the registry.is there any possible way to achieve this.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,678 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,292 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,540 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Reza Aghaei 4,936 Reputation points MVP
    2022-07-19T23:12:44.87+00:00

    You can use ManagementEventWatcher and watch Win32_ProcessStartTrace to receive an event when a new process starts.

    The following example shows how you can detect when OSK.exe starts:

    using System.Management;  
    using System.Windows;  
    namespace WpfApp1  
    {  
        public partial class MainWindow : Window  
        {  
            public MainWindow()  
            {  
                InitializeComponent();  
            }  
            ManagementEventWatcher watcher;  
            private void Window_Loaded(object sender, RoutedEventArgs e)  
            {  
                watcher = new ManagementEventWatcher(  
                "Select * From Win32_ProcessStartTrace Where ProcessName = 'osk.exe'");  
                watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);  
                watcher.Start();  
                this.Title = "Waiting for OSK.exe to run ...";  
            }  
            void watcher_EventArrived(object sender, EventArrivedEventArgs e)  
            {  
                Dispatcher.Invoke(() => this.Title = "OSK.exe is running now.");  
            }  
            private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)  
            {  
                watcher.Stop();  
                watcher.Dispose();  
            }  
        }  
    }  
    
    1 person found this answer helpful.
    0 comments No comments