473,498 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automating input

Is there any way of getting VS2005 to 'type' the content of a file into the
currently open CS file?

I am trying to capture the VS2005 screen: I'd like to be able to record the
code (already stored in a file) being typed; doing this manually is fraught
with problems and I wondered whether I bring in the code from a file,
character by character.
Oct 18 '07 #1
7 1417
On Oct 18, 8:54 am, AA2e72E <AA2e...@discussions.microsoft.comwrote:
Is there any way of getting VS2005 to 'type' the content of a file into the
currently open CS file?

I am trying to capture the VS2005 screen: I'd like to be able to record the
code (already stored in a file) being typed; doing this manually is fraught
with problems and I wondered whether I bring in the code from a file,
character by character.
Well, you could do it with another process calling SendKeys.Send/
SendWait.
It's crude, but it appears to work.

Jon

Oct 18 '07 #2
Easy enough to simulate - just use following as console exe and feed
it the file(s) as input args:

using System;
using System.IO;
using System.Windows.Forms;
using System.Threading;
static class Program {
static void Main(string[] args) {
Console.WriteLine("Select your app!");
Thread.Sleep(5000);
Console.WriteLine("Typing...");
foreach (string arg in args) {
using (StreamReader reader = File.OpenText(arg)) {
char[] escapeBuffer = { '{', '?', '}' };
while (!reader.EndOfStream) {
char c = (char)reader.Read();
string keys;
switch (c)
{
case '+': case '^':
case '%': case '~':
case '{': case '}':
case '[': case ']':
case '(': case ')':
escapeBuffer[1] = c;
keys = new string(escapeBuffer);
break;
case '\t':
keys = "{TAB}";
break;
case '\n':
keys = "{ENTER}";
break;
case '\r':
if (reader.Peek() == '\n') {
reader.Read();
}
keys = "{ENTER}";
break;
default:
keys = new string(c,1);
break;
}
try { SendKeys.SendWait(keys); }
catch (Exception ex) {
Console.Error.WriteLine(ex);
}
Thread.Sleep(100);
}
}
}
}
}
Oct 18 '07 #3
Thanks for the hint, Jon, and for the solution-which I am about to try
out-Marc.

Oct 18 '07 #4
Following makes large indents (lots of spaces) and comments (lots
of ------ etc) less painful:

default:
int count = 1;
while (reader.Peek() == c)
{
count++;
reader.Read();
}
keys = new string(c,count);
break;

Marc
Oct 18 '07 #5
Marc, thanks again for this.

I tried it out and it works; I needed to add a reference to
System.Windows.Forms to compile the code.

The file contents gets typed into the selected application.

Just one small point/refinement:

Having selected the application, it exe starts typing in that application's
window; howevr, if you switch to another window, the typing location changes
to that window: I can live with this but is there a way to 'lock' or 'fix'
the target window?
Oct 18 '07 #6
not using SendKeys; you'd have to use a different approach
unfortunately - and it isn't something I've had to do

I tried it a minute ago, and it also appears to fight VS when it comes
to leading whitespace - you could probably fix this by (if you know VS
is the target) keeping track if you have just started a new line (i.e.
nothing has been sent since the last {ENTER}), and disregard space
until something interesting appears. Maybe ;-p

Marc
Oct 18 '07 #7
Marc Gravell wrote:
[...] I tried it a minute ago, and it also appears to fight VS when it comes
to leading whitespace [...]
Isn't there a way to turn off the auto-indent stuff in VS?

I don't have a quick way to check it at the moment, but it would
surprise me if that was a behavior that is forced on the user.

Pete
Oct 18 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4315
by: Charles Banas | last post by:
weird subject - i hope more than just one curious regular will hear me out. :) ok, i've got a bit of a big problem, and i need answers as soon as possible. i know this forum is meant for web...
7
2610
by: xzzy | last post by:
I need to automate a report in a different database (and thank yous to Terry Kreft for pointing me in the right direction). below is the code with the one line that does not work, marked: 'Does...
6
630
by: Mark Gross | last post by:
I am attempting to programatically drive a Lotus Notes web application from a VB.NET database application (who wants to rekey information in one database into someone else's web page for entry to...
4
3213
by: Supa Hoopsa | last post by:
I am in the process of rewriting an MS Access application (access front end with SQL 2k database) in VB.NET and one of the things I would like to do is link in to the compiled Access ADE so that I...
1
969
by: Vlado Jasovic \(excelleinc.com\) | last post by:
Hello, I am developing application with 100+ controls on it. I would like to find a way to automate user input so we don't have our QA guy manually inserting different cases/scenarios. ...
17
3335
by: Franc Zabkar | last post by:
My D-Link DSL-302G modem/router has a real-time clock whose settings are volatile. To avoid hand keying the date/time via the modem's JS interface, I wonder if there is a way to copy the JS code to...
2
1342
by: Dave | last post by:
I have to download files every day from a web based application and it's getting very repetitious. I would like to find a way to automate the task. What I have to do each day is go to a website...
4
3180
by: attachmatey | last post by:
Greetings: I'm looking for some help in automating (what I thought would be) a simple procedure in Internet Explorer. I'm trying to put the following operation under a button click in an MS...
0
1268
by: totomalas | last post by:
I have developed a report in Access 2007 that runs on three queries, each promting an input from the user...this report is used for a meeting and it should be printed nine times...what I do now is...
5
2877
by: totomalas | last post by:
I have developed a report in Access 2007 that runs on three queries, each promting an input from the user...this report is used for a meeting and it should be printed nine times...what I do now is...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.