windows inputlanguage changed c# - c#

I am working on a simple program in Visual studio(windows application) and I need to know when the user is changing the keyboard language(I don't care what was the language or what it is now).
I have tried this code:
private void MainForm_InputLanguageChanged(object sender, InputLanguageChangedEventArgs e)
{
}
But it will only get the language change in the form when the form is active and focused! Example: I'll open Google chrome and change the language, this function will not be called.
I need to get the specific windows keyboard changed. Not the form inputlanguage changed..
it's very important for me I am breaking my head about a week for this so please help.
ty guys.

As far s I know, in Windows, input language is specific for process. So you get the InputLanguageChanged event for your application. If you want to be notified of language change globally, you should do it on your own. For example periodically check the active window and get keyboard layout using GetKeyboardLayout API function.

Related

How to programmatically add/modify/delete available display settings (width, height, refresh rate)?

I want to code (in C#) a tool to add/modify/delete some of the available Windows display configurations (width, height and refresh rate).
Can this be done programmatically? I've spent many hours trying to find something about this online but had no luck.
The reason i want it is because of some older full screen games that keep setting the refresh rate back to 60hz from whatever it were when the game started (120hz in my case). I can solve that problem using Alt-Tab twice but I rather want to just limit the available display configurations (or change the refresh rate for some of them) instead.
Before considering all this I've tried to solve my problem with these attempts:
Intercepting the keyboard (using this class Global keyboard capture in C# application) and then attempt a force display change when a hotkey it pressed. It works fine for just about all normal apps. But when a full screen game is running the keydown event doesn't fire. Either it is not possible when a full screen game has focus or I don't just know how to do it properly (very likely as I am a newbie in that regards).
Tried using a timer to periodically check for a certain resolution and if 60hz is detected then try to set it to 120hz. The timer does fire and the code tries to change the monitor (which flickers briefly) - but the refresh rate doesn't change.
Another idea I had was to use Mhook or Detours to intercept the 'change display setting'-call. But I don't know if that'll work. And I also have no experience with C++. So I really don't want to go that way if I can avoid it.
Can this be programmatically? I've spent many hours trying to find
something about this online but had no luck.
This settings are not part of the standard .Net Framework but there is interface to manipulate these settings for windows problematically using win32 APIs. you can look here on how to call windows APIs using .Net Framework. then you can call a windows API to change the resolution for instance.

Registering a global keyboard shortcut across all applications

I'm trying to create an application that will process selected text when a keyboard shortcut is pressed. I used part of this method to get the currently selected text (and there seems to be no other way to get the selected text from any application:
string GetSelectedText()
{
var oldClip = Clipboard.GetText();
SendKeys.SendWait("^c");
string selection = Clipboard.GetText();
Clipboard.SetText(oldClip); // preserve clipboard
return selection;
}
My first thought was to use a system tray icon. When clicked, the icon would use the above method to get the current selection, and process it. However, using the clipboard like that requires the application to be in focus, whereas clicking a system tray icon brings the icon into focus before the method can run.
My next thought was to use a global keyboard shortcut. I came across this article about getting a global hotkey, and it could in fact listen to keyboard combinations, but only within one app, which is not what I want - I want to listen to the keyboard shortcut across any app.
I have already read this article (which came from this answer) which does manage to listen for keys across any app but only manages to listen to one key at a time (e.g. a single LControl, or Shift, or C, etc).
My question here is: How can I listen for a certain combination of keys, no matter what application is in focus, and execute the method above to get the current selection?
If there is a better way to retrieve the current selection, or if it can be done when the application is not in focus, answers explaning how it is possible are also appreciated; the main focus, however, is listening for a keyboard combination across all applications.
I ended up using the library that Chris Dunaway mentioned, MouseKeyboardLibrary.
As you may have seen in the comment thread where he brought it up, it initially didn't work for me. It turned out that the library didn't work for me because of an invalid module IntPtr, so I changed the library to use IntPtr.Zero where it previously used Marshal to get the module pointer, which made it work as expected.

Windows Phone c# how to catch global hook

I have simple app:
public MainPage()
{
InitializeComponent();
CameraButtons.ShutterKeyPressed += OnButtonFullPress;
}
private void OnButtonFullPress(object sender, EventArgs e)
{
//camera button pressed
}
When my app is active, all is great, but, when my app is not active, i cant catch, when camera button were pressed.
Is this possible with default SDK?
There is a way to set your application as a default camera app on windows phone 8, but this feature is only available for 'special' developers like Microsoft, Nokia or other hardware companies. So it's not possible for you, most probably.
http://forums.windowscentral.com/windows-phone-8/234751-changing-default-camera-app.html
Also if you look at the application lifecycle you'll see that after user minimizes your app it might be tombstoned and even unloaded from the memory. So, you loose the control over the device resources. That means that you can't get any events except the awake event.
The third option you have is to run the app under the lock screen, but it doesn't fit you as well. There is a limited set of api's you can use in this mode. (Location and Audio).
So I'm sorry, but you can't do anything so far.
Unfortunately, this is not possible for third-party developers. You can only access the hardware buttons while your applications is running.

C# - Transparent Window to defeat Keyloggers

How can I create a window which is fully apparent to the user but is not visible in screenshots. I know that this is possible since Neo SafeKeys (an onscreen keyboard to defeat keyloggers) does not appear in the screenshots taken by keylogging software I installed.
To give you an idea, the window is fully visible to the user, however when a screenshot is taken, the Neo SafeKeys window does not appear at all (as if it does not even exist).
Neo SafeKeys states that it uses an invisible protection layer above the window to protect against screenshots. I have searched all over the internet to see how can I reproduce this, to no avail. Does anybody know how this can be performed (windows which is visible to user but invisible in screenshots)?
What you can do is you can prevent the PrtScn key from doing anything when pressed. Take a look at this article while shows you how to do this.
What this article is doing is clearing out the clipboard. What you can do instead is capture the screen image and digitally remove your application, then put the revised image on the clipboard, thus giving the "Effect" of making your window transparent.
Also, you might want to look at this SO question which gives an alternative way to make your window just appear "blue", though its not easy to do.
Does anybody know how this can be performed (windows which is visible to user but invisible in screenshots)?
Use DirectX to render directly to the device.
In your C# application you can set up a global hook to monitor keyboard events. Then your application becomes the global handler for print screens. Now if another application managed screen prints natively, can't stop that, but anything running through windows, you can get at.
The WM_KEYBOARD_LL hook is one of the few global hooks that can be used in managed code because it doesn't require a DLL to be injected into every target.
For some code you can visit here:
Adam's Blog
Keep in mind that these are global hooks so you want to make sure nothing else (other applications) are effected. I've used these in the past as we hosted showing a power point in an application we worked on. Basically we didn't want the user to invoke any powerpoint menus or keyboard short cuts so we used a global hook. We always checked to see whether the users was in a certain area (screen) and in our application, otherwise we would effect other applications functionality (including our own!)
Microsoft Information:
Hooks Overview
There's this.....
visual cryptography
live example here
But this could be easily coded against by taking multiple screenshots and laying them overeachother and such...
If you are using Windows, and you can avoid that screenlogging happens, you can implement a nice solution like a virtual desktop to embed your process into it. When a process is running inside a virtual desktop it is possible to bypass an screenlogger tool that runs over win32 Api.
Check out this article so you can sneak a peek how to implement a nice solution to scape from screen and keyboard monitoring.
http://www.codeproject.com/Articles/7392/Lock-Windows-Desktop?fid=62485&select=3139662&fr=101#xx0xx

how to programmatically click on a button in running app using C# code

I want to write a C# program which will launch an .exe (this is an easy job, I know how to do it.) but now I want to add some more functionality to it.
I want to take user inputs to my program and want to pass them to running .exe as a input.Also I want to click on a particular button available on the exe window. Important thing is, I want to do it programatically without user knowledge that we are actually running that exe in background.
Please let me know if it is possible. It is very urgent.
Yes it is possible with Windows API. You need to send a message to that Window. At first use Spy++ to get IDs of all buttons you want to click. Spy++ is a Visual Studio tool and it shows you what messages are being sent to the application when you press those buttons. Then use PostMessage() function (Windows API) to send the same message programatically.
You can also for example look at Winamp (a music player for windows), there is documentation on how to press its buttons from external app. You can do it the same way for other apps, you just need to know IDs of all controls and names of windows or their classes.
here is code to click on Winamp's pause button:
#define AMP_PAUSE 40046
HWND hwnd = FindWindow("Winamp v1.x", 0);
if(hwnd) SendMessage(hwnd, WM_COMMAND, AMP_PAUSE, 0);
This is written in C++. If you do it in C#, use PInvoke to get access to Windows API. I assume you know how to do this. In the first step FindWindow gets a handle to the window, it identifies it by the name of its class. Then we use SendMessage or PostMessage to send the message. There are four parameters: window to send the message to, message id, and two parameters.
In Spy++ you can find those parameters you need for FindWindow and SendMessage. Please start it and play with it a little bit to see what it can do.
If you want to avoid directly use of WIN API, there's a small library that can help you with this, WindowScrape.
You can use it directly from C#.
Some of the features:
Search for windows and child controls registered in memory.
Change the titles of windows
Change the text of UI elements (permissions/privacy permitting)
Click on UI elements
Read the Titles of windows
Read the text from UI elements
Navigate through object hierarchies
Set object locations
Set object sizes
There might be other similar libraries, but at this point this is the only one that i'm aware.
Edited
Sample Usage:
using System.Windows.Forms;
//WindowScrape
using WindowScrape.Types;
namespace WindowsFormsTestApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var npad = HwndObject.GetWindowByTitle("Untitled - Notepad");
}
}
}
If it is a WPF application you could have a look at AutomationPeers

Categories

Resources