Sendkeys.send send alt+space+n combination - c#

The title pretty much explains question. I want to sen alt+space+n combination via Senkeys.send method, how this could be done? So far I've tried SendKeys.Send("% N"); but it's not working.

Spacebar isn't a traditional modifier key, so I believe you will need to send the keyUp and keyDown events seperately.
I'm not completely familiar with C# sendkeys, since I use the AutoIt library for this kind of thing, with AutoIt the commands would be something like:
private void pressAltSpaceN()
{
AutoItX3Declarations.AU3_Send("{alt down}", 0);
AutoItX3Declarations.AU3_Send("{space down}", 0);
AutoItX3Declarations.AU3_Send("{n down}", 0);
AutoItX3Declarations.AU3_Send("{n up}", 0);
AutoItX3Declarations.AU3_Send("{space up}", 0);
AutoItX3Declarations.AU3_Send("{alt up}", 0);
}
Hopefully someone else can tell how to send keyUp and keyDown events using SendKeys, otherwise you can learn how to integrate AutoIt into C# using the answer to this question: link.

The string you're using should work. Perhaps the default journaling hook doesn't work with the application you're trying to minimize. You could try using the alternate method using app.config and SendInput (see here).
A better way to solve the problem would be to obtain a handle to the focused window using GetActiveWindow, then call ShowWindowAsync and pass in a ShowWindowCommand value of 2.

Related

g_main_loop_run() freeze the window

I am trying to create a video player in C# using the functions imported from the GStreamer library by Pinvoke. It's looking nice so far, but if I add g_main_loop_run(loop); my C# application freezes and I just can't click any button or move my window.
I think that the problem may involve gmaincontext, but I don't know exactly what the problem is or how to resolve it.
Here is my C++ code in my library:
GstElement *pipeline;
void seek_to_pos(double position) {
gint64 len;
gst_element_query_duration(pipeline, GST_FORMAT_TIME, &len);
gst_element_seek_simple(pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, len*position);
}
void play_file(char* path_to_file, void* hwnd_ptr_of_window){
gst_init(NULL, NULL);
HWND hwnd = (HWND)hwnd_ptr_of_window;
GMainLoop *loop = g_main_loop_new(NULL, FALSE);
pipeline = gst_element_factory_make("playbin", "player");
g_object_set (G_OBJECT (pipeline), "uri", path_to_file, NULL);
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(pipeline), (guintptr)hwnd);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
g_main_loop_run(loop);//problem
}
Without the g_main_loop_run(loop); string, all works fine, but of course I need it for some another things.
Also, I already know that I need to run GMainLoop in a
different thread to not block my C# application's event loop but I don't know exactly how I can do it.
So I need a code sample or link which describes how I can do it right. Thanks!

emulate input for dos application

i have to input some data into an really old dos application and wanted to automate this. first i tried SendKeys, which failed, after that i tried the InputSimulator (inputsimulator.codeplex.com) which failed too. It works in any other Application (even cmd...) but not in the application i want to...
sample code i used:
InputSimulator.SimulateTextEntry("test");
InputSimulator.SimulateKeyDown(VirtualKeyCode.F1);
InputSimulator.SimulateKeyUp(VirtualKeyCode.F1);
i also tried it with SimulateKeyPress, same results :(
can someone please give me some hints?
Target System: Win XP
Screen of the app:
http://images.devs-on.net/Image/wxhZouyZdwemgTRp-Bereich.png
EDIT1: is it possible to start the .bat from my application and stdin the input?
EDIT2: as Boluc Papuccuoglu pointed out the stdin approach won't work. so is there anyway to code a working keystrokes emulating function?
EDIT3: with keybd_event i got it to write to the application. BUT... i tried it with
public const int A = 0x41;
public const int C = 0x43;
keybd_event(A, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(A, 0, KEYEVENTF_KEYUP, 0);
System.Threading.Thread.Sleep(1000);
keybd_event(C, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(C, 0, KEYEVENTF_KEYUP, 0);
but i only get 2 times "a".
EDIT4: doesn't matter which Virtual Key i give to keybd_event, he is always writing "a" and nothing else. seems like i have to do it the old fashioned aka manual way.
EDIT5: so yeah, manual entry sucked, so i decided to give autoit a try and it works. WTF? maybe someone can explain me how autoits way of sending keys to a program is different then sendkeys, inputsimulator and keybd_event.
Unfortunately the stdin approach probably will not work. From what I can see in the screenshot, the application most probably acts on keypresses, not the contents of the input stream.

How to make keybd_event handle more than two key presses at once?

Im using keybd_event win api call in C# and i want to simulate special key presses, like alt+f4, alt+tab and similar. My program can handle "simple" key presses, like shift+p, altgr+w and simple use of tab, or enter are also working, but when two special buttons present (for special buttons i mean alt, shift, ctrl or functional buttons) it seems it does nothing. My program should handle multiple forms through remote desktop, thats why im using this keybd_event call, but for example alt+f4 doesnt work even locally (im testing on a notepad, but i cannot close it with this command). Anyone has idea what am i doing wrong? Is it even possible to make them work?
Thanks in advance!
Edit:
I have created a DLLImport class in which i stored all the win api calls. I also have some helper methods, for example:
private void PressAlt()
{
DLLImport.keybd_event(0xA0, 0x38, 0, 0);
}
private void ReleaseAlt()
{
DLLImport.keybd_event(0xA0, 0x38, 0x0002, 0);
}
For tab, im using this in a separate method:
DLLImport.keybd_event(0x09, 0x0f, 0, 0); //press tab
...
DLLImport.keybd_event(0x09, 0x0f, 0x0002, 0); //release tab
And im now testing it with:
PressAlt();
PressSpecial("tab");
ReleaseSpecial("tab");
ReleaseAlt();
From the code you posted, it looks like you have the wrong values for at least one of the virtual key codes (MSDN reference here).
For example, the code 0xA0 is the Left Shift key (VK_LSHIFT), you should try 0x12 (VK_MENU) or 0xA4 (VK_LMENU) instead.
Note - there is a useful summary of common virtual key codes and scan codes on CodeProject.

CallWndProc hook not receiving all messages

I am making a little tool like Displayfusion and I need some Hooks to receive messages when Windows move/activate/etc , however I'm stuck..
I am using this project for the CallWndProc hook:
http://www.codeproject.com/KB/system/WilsonSystemGlobalHooks.aspx
For pretty much all windows it works great(x86 and x64), however on some windows it seems to can't inject the hook DLL. Currently I am having problems with adobe reader X. No messages are being received from that window. I think it has something to do with the sandbox? Can somebody give me a push in the right direction?
The initialization code for the hook:
bool InitializeCallWndProcHook(int threadID, HWND destination)
{
if (g_appInstance == NULL)
return false;
if (GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC") != NULL)
SendNotifyMessage((HWND)GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC"), RegisterWindowMessage("WILSON_HOOK_CALLWNDPROC_REPLACED"), 0, 0);
SetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC", destination);
hookCallWndProc = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProcHookCallback, g_appInstance, threadID);
return hookCallWndProc != NULL;
}
Hmm, try if Spy++ can catch the messages. If it can, then obviously it's not a problem with security measures. It Spy++ can't however, then it's pretty much impossible.
See if this works: Use both WH_CALLWNDPROC and WH_GETMESSAGE hooks, since apparently, the former only catches sent message, and the latter only catches posted messages.
I have a similar Problem in my application. Visit the following link:
Strange behaviour of windows hooks
My guess ist that an application interrupts the filter function chain by not calling the CallNextHookEx method. Note that is this only possible when you are using WH_CBT hooks.

C# - Popup my application whenever print happened to test driver

I am working on the assignment to write a Virtual Printer with C# and NTDDK.
I have created a test printer driver and I am able to print .ps documents(redirected to C:\test\test.ps always) using it. But now I have to write a small application that will popup a messagebox saying "Print is done" using C# but I am not able to figure out how to do it?
Can anyone help me in this?
Thanks in advance!
Use the endprint event...that is something like, in the designer code put:
///////////////
something.EndPrint += new PrintEventHandler(endingclass);
//////////////
in the form constructor, or anywhere in the program/form where you can call the method put:
private void endingclass(object sender, PrintEventArgs e)
{
MessageBox.Show("wazaaaaaaaaaaaaaaaaa");
}
////////
Obviously, you need to make some...arrangements in the code above - but I believe they are self evident. In case you have problems, googl the endprint event, it will 100% has some examples associated with it.
////
On a side note...if you're really bored you can think of asynchronous process which checks the process every....1/10 of a second :). It will work, but it's a bizarre way to accomplish such a thing. Since you're a c++ developer, c# should be easy to you, you'll like it, it's more powerfull than c++ anyway.

Categories

Resources