Reputation: 3976
We are going to create a virtual keyboard (on screen keyboard) with customized keys (no Ctrl, Alt and ...).
The problem is when we set the application to be Topmost="Ture"
then it is not possible to find the last active application's window to send the selected key to it. (The keyboard application is now the active one.)
We did a few search but couldn't find anything helpful.
Upvotes: 3
Views: 1066
Reputation: 3976
Thanks for your help and answers. I find Wosk and it solved my problem. You can review the code.
Upvotes: 0
Reputation: 37566
Keep a handle to the last window before you set the prperty to true, take a look at GetForegroundWindow() or GetActiveWindow(), then use a the SetActiveWindow() to set it back after done with your keyboard application.
using System;
using System.Runtime.InteropServices;
namespace Foreground {
class GetForegroundWindowTest {
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetForegroundWindow();
public static void Main(string[] args){
IntPtr fg = GetForegroundWindow(); //use to keep the last active window
// set the topmost property to your keyboard
//Set fg to be active again when needed using SetActiveWindow()
}
}
}
Upvotes: 3