Jump to content

Launch Programs and do keypresses in C#?

Ok. Fist and foremost. I am a total programming nube.

 

Using C# and visual studio, I want to make an exicutable file written in C# that does the following:

 

  1. Launches google chrome
  2. Presses "CTRL + N" repeatedly forever.

 

Thats it. I could write this in as a unity game too.

 

Thanks!

 

Since I am to lazy to put something interesting here, I will put everything, but slightly abbreviated. Here is everything:

 

42

 

also, some questions to make you wonder about life:

 

What is I and who is me? Who is you? Which armrest in the movie theatre is yours?

 

also,

 

Welcome to the internet, I will be your guide. Or something.

 

 

My build:

CPU: Intel Core i5-7400 3.0GHz Quad-Core Processor,

 Motherboard: ASRock B250M Pro4 Micro ATX LGA1151 Motherboard, 

Memory: Corsair 8GB (1 x 8GB) DDR4-2133 Memory,

Storage: Seagate Barracuda 1TB 3.5" 7200RPM Internal Hard Drive, 

Video Card: MSI Radeon RX 480 4GB ARMOR OC Video Card, 

Case: Corsair 100R ATX Mid Tower Case , 

Power Supply: Corsair CXM 450W 80+ Bronze Certified Semi-Modular ATX Power Supply, 

Operating System: Microsoft Windows 10 Home Full, 

Wireless Network Adapter: TP-Link TL-WN725N USB 2.0 802.11b/g/n Wi-Fi Adapter, Case Fan: Corsair Air Series White 2 pack 52.2 CFM  120mm Fan

 

ou do not ask why, you ask why not -me

 

Remeber kinds, the only differ between screwing around and scince is writing it down. -Adam Savage.

 

Only two things are infinite: the universe and human stupidity, and I'm not even sure of the former. - Albert Einstein.

Link to comment
https://linustechtips.com/topic/845485-launch-programs-and-do-keypresses-in-c/
Share on other sites

Link to post
Share on other sites

For the fist thing just search for Process.Start and ProcessStartInfo, those are probably everything you need. Second depends heavily on what you are trying to achieve and on the machine it's being run on. However SendKeys may work perfectly for your situation, just don't expect it to be completely reliable.

Link to post
Share on other sites

3 hours ago, zwirek2201 said:

 

1 hour ago, jubjub said:

Ignore the first person telling you too google it because you're asking here for a reason. For the fist thing just search for Process.Start and ProcessStartInfo, those are probably everything you need. Second depends heavily on what you are trying to achieve and on the machine it's being run on. However SendKeys may work perfectly for your situation, just don't expect it to be completely reliable.

Does sendKeys work with 2 keys.

 

As stated in my post, I need it to press CTRL+N.

 

How would I assure it presses ctrl, then n, then lifts n, then lifts ctrl?

 

Since I am to lazy to put something interesting here, I will put everything, but slightly abbreviated. Here is everything:

 

42

 

also, some questions to make you wonder about life:

 

What is I and who is me? Who is you? Which armrest in the movie theatre is yours?

 

also,

 

Welcome to the internet, I will be your guide. Or something.

 

 

My build:

CPU: Intel Core i5-7400 3.0GHz Quad-Core Processor,

 Motherboard: ASRock B250M Pro4 Micro ATX LGA1151 Motherboard, 

Memory: Corsair 8GB (1 x 8GB) DDR4-2133 Memory,

Storage: Seagate Barracuda 1TB 3.5" 7200RPM Internal Hard Drive, 

Video Card: MSI Radeon RX 480 4GB ARMOR OC Video Card, 

Case: Corsair 100R ATX Mid Tower Case , 

Power Supply: Corsair CXM 450W 80+ Bronze Certified Semi-Modular ATX Power Supply, 

Operating System: Microsoft Windows 10 Home Full, 

Wireless Network Adapter: TP-Link TL-WN725N USB 2.0 802.11b/g/n Wi-Fi Adapter, Case Fan: Corsair Air Series White 2 pack 52.2 CFM  120mm Fan

 

ou do not ask why, you ask why not -me

 

Remeber kinds, the only differ between screwing around and scince is writing it down. -Adam Savage.

 

Only two things are infinite: the universe and human stupidity, and I'm not even sure of the former. - Albert Einstein.

Link to post
Share on other sites

9 minutes ago, King_of_Oz said:

 

Does sendKeys work with 2 keys.

 

As stated in my post, I need it to press CTRL+N.

 

How would I assure it presses ctrl, then n, then lifts n, then lifts ctrl?

SendKeys.Send("^N");

 

Since ^ will perform CTRL while doing N. If you want to do multiple keys you'd do "^(NE)" which would do CTRL+N+E as "^NE" would do CTRL+N E.

 

Although it's not really that reliable but it will probably work for your situation.

Link to post
Share on other sites

19 minutes ago, jubjub said:

SendKeys.Send("^N");

 

Since ^ will perform CTRL while doing N. If you want to do multiple keys you'd do "^(NE)" which would do CTRL+N+E as "^NE" would do CTRL+N E.

 

Although it's not really that reliable but it will probably work for your situation.

Thanks!

 

Since I am to lazy to put something interesting here, I will put everything, but slightly abbreviated. Here is everything:

 

42

 

also, some questions to make you wonder about life:

 

What is I and who is me? Who is you? Which armrest in the movie theatre is yours?

 

also,

 

Welcome to the internet, I will be your guide. Or something.

 

 

My build:

CPU: Intel Core i5-7400 3.0GHz Quad-Core Processor,

 Motherboard: ASRock B250M Pro4 Micro ATX LGA1151 Motherboard, 

Memory: Corsair 8GB (1 x 8GB) DDR4-2133 Memory,

Storage: Seagate Barracuda 1TB 3.5" 7200RPM Internal Hard Drive, 

Video Card: MSI Radeon RX 480 4GB ARMOR OC Video Card, 

Case: Corsair 100R ATX Mid Tower Case , 

Power Supply: Corsair CXM 450W 80+ Bronze Certified Semi-Modular ATX Power Supply, 

Operating System: Microsoft Windows 10 Home Full, 

Wireless Network Adapter: TP-Link TL-WN725N USB 2.0 802.11b/g/n Wi-Fi Adapter, Case Fan: Corsair Air Series White 2 pack 52.2 CFM  120mm Fan

 

ou do not ask why, you ask why not -me

 

Remeber kinds, the only differ between screwing around and scince is writing it down. -Adam Savage.

 

Only two things are infinite: the universe and human stupidity, and I'm not even sure of the former. - Albert Einstein.

Link to post
Share on other sites

On 10/12/2017 at 7:38 AM, King_of_Oz said:

 

As stated in my post, I need it to press CTRL+N.

 

How would I assure it presses ctrl, then n, then lifts n, then lifts ctrl?

 

he teaches some relevant stuff here. He recommends msdn documentation for c#, and I recommend that documentation too. 

Link to post
Share on other sites

1 hour ago, fpo said:

 

he teaches some relevant stuff here. He recommends msdn documentation for c#, and I recommend that documentation too. 

Thanks!

 

Since I am to lazy to put something interesting here, I will put everything, but slightly abbreviated. Here is everything:

 

42

 

also, some questions to make you wonder about life:

 

What is I and who is me? Who is you? Which armrest in the movie theatre is yours?

 

also,

 

Welcome to the internet, I will be your guide. Or something.

 

 

My build:

CPU: Intel Core i5-7400 3.0GHz Quad-Core Processor,

 Motherboard: ASRock B250M Pro4 Micro ATX LGA1151 Motherboard, 

Memory: Corsair 8GB (1 x 8GB) DDR4-2133 Memory,

Storage: Seagate Barracuda 1TB 3.5" 7200RPM Internal Hard Drive, 

Video Card: MSI Radeon RX 480 4GB ARMOR OC Video Card, 

Case: Corsair 100R ATX Mid Tower Case , 

Power Supply: Corsair CXM 450W 80+ Bronze Certified Semi-Modular ATX Power Supply, 

Operating System: Microsoft Windows 10 Home Full, 

Wireless Network Adapter: TP-Link TL-WN725N USB 2.0 802.11b/g/n Wi-Fi Adapter, Case Fan: Corsair Air Series White 2 pack 52.2 CFM  120mm Fan

 

ou do not ask why, you ask why not -me

 

Remeber kinds, the only differ between screwing around and scince is writing it down. -Adam Savage.

 

Only two things are infinite: the universe and human stupidity, and I'm not even sure of the former. - Albert Einstein.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×