user1966548
user1966548

Reputation:

Alt+F,S not working in sendKeys C#

I want to save and close all kinds of application which is opened. The specific application is identified from Process command. with this I can kill it.

For saving I tried SendKeys class, First I set the SetForegroundWindow(h), and succeeded with ctrl+s by using

SendKeys.Send("^s"); //Ctrl+s

but, user defined applications are there, and also I have a situation to save a new(not existing file) which has to be saved by Alt+F+S. So that it saves with default name How do I achieve this, I tried,

SendKeys.Send("%(fs)");
SendKeys.Send("%f"+"s"); //Alt+F 
SendKeys.Send("%f" + "%s)"); //Alt+F
SendKeys.Send("%fs"); 

Please guide me, If its not possible with SendKeys, what else should I try.

Upvotes: 0

Views: 14248

Answers (2)

C0d1ngJammer
C0d1ngJammer

Reputation: 550

Always use the breakets and you can avoid errors.

SendKeys.Send("%{f}"); //Alt+F
SendKeys.Send("{A}"); //A

or try

SendKeys.Send("%{f}{A}"); //Alt+F And A

Upvotes: 5

Steve Drake
Steve Drake

Reputation: 2058

What APP? SendKeys will send key strokes but under the hood most things use the good old message loop.

SendMessage(hWnd, WM_SETTEXT, wParam, lParam);

c#

[DllImport("user32.dll")]    
public static extern IntPtr FindWindow(string lpClassName, String lpWindowName);    
[DllImport("user32.dll")]    
public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);    
[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern uint RegisterWindowMessage(string lpString);

IntPtr hwnd= FindWindow(null, "Window Title");    
SendMessage(hwnd, id, IntPtr.Zero, IntPtr.Zero);

To get notepad to save it would be

const int WM_COMMAND = 0x111;     
SendMessage(hwnd, WM_COMMAND,777  , NULL);

Upvotes: 1

Related Questions