How can i make program press button for me C# - c#

How can I make console program in C# press and hold numlock7 key for me. So that can run in background even if console app is not selected. Can you please tell me method to do that, or atleast class that can I look into.
Thanks

System.Windows.Forms.SendKeys.Send()

Related

Calling a method at any time in a console application based on certain key being pressed in c#?

I am trying to practice what I have learned so far in c# by creating random applications. I have been working on a Console text adventure style game.
I created a method to clear the screen after a user hits any key.
This works but I have been looking for a way to be able to call my method at any time during the console application when the user hits a certain key. That way I don't have to randomly call this method as I write the code for the game and can give the player the ability to do it when they feel ready to.
For example, I want to be able to tell them from the very beginning something like hit c at any time during the game to clear the screen without messing up where they currently are in the game. Is there any way to accomplish this?
or another example would be something like hit h at any time during the program to check your health?
Any ideas on how to make that work or what I need to look into to make either of those ideas work would be greatly appreciated.
Thank You
static void clearScreen()
{
Console.WriteLine("\n Please press enter to clear the screen and continue");
Console.ReadLine();
Console.Clear();
}

Code to keep the command window open after code finishes executing

So I’m learning about C# with visual Studio, I wrote a small program kind of like a “hello world”,
I remember that with C++ md Java there is a conman you wrote at the end of your code o hav the command window stay on after the program finishes running. My question is, or C#, what is that code or command I’m supposed to write so that when I debug it and it runs the command window doesn’t closes after I finish with he user input?
You are looking for:
Console.Write("\nPress any key to continue... ");
Console.ReadLine();
This will keep window open until you press Enter key

Automatically pause the console application in c#

I know I can use Console.ReadKey(); or Console.ReadLine(); to wait for the user input.
I am following some video tutorials from youTube
There I notice that when the tutor writes some code like
Console.WriteLine("This is a basic C# tutorial");
He gets a message saying Press any key to continue...
So, I want to know how to get the above message without writing any code for displaying the message.
Run without debugging sounds like what you want. Ctrl + F5.

Getting started with C#, how to Debug .NET 4.0 MVC3 Project?

I am trying to self teach myself C# and wondering if anyone can help me with what seems to be a basic C# question. I created a C# file with this code, started debugging but don’t see “Hello World” anywhere.
using System;
class Hello
{
static void Main() {
Console.WriteLine("hello, world");
}
}
http://msdn.microsoft.com/en-us/library/aa664628(v=vs.71).aspx
So I guess my question is this. Where should I expect to see “Hello World”? I have checked the Console and the Browser. Is there some setup that needs to be done to properly debug C# files. I am probably missing the big picture as to how C# works. I am use to PHP where I can just do something like this...
<?php
include 'my file';
echo 'my file included';
?>
Any help would be much appreciated. Thanks.
EDIT:
Thanks everybody for all of the help. You have all helped me understand and realize a number of things about C# / .NET. After extensive troubleshooting it is evident that the problem is not a mater of the debugging working, but the fact that my C# file doesn't appear to be properly hooked/included (not sure what its called in .NET terms) to the rest of the project. Anyways I am accepting keyboardP's answer as he answered first and technically gave me all the right answers. Also thanks to dasblinkenlight who was also extra helpful.
Additional Solution:
After insight from SO users. This article helped point me in the right direction.
http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/intro-to-aspnet-mvc-3
I'm guessing it's because the command prompt window is immediately closing. You can avoid this by adding Console.ReadLine(); after your WriteLine statement. This will wait for you to press return before closing the prompt window.
Alternatively, assuming you're using Visual Studio, you can run the build without a debugger attached by pressing CTRL + F5.
Edit - Based on the extra information added that you're using ASP.NET and not a console application.
Firstly, what are you trying to achieve? If you want to output debug information, then you can Debug.WriteLine instead of Console.WriteLine
System.Diagnostics.Debug.WriteLine("Hello World");
This will output the text to the "Output" window at the bottom of Visual Studio (by default).
Edit 2 Since you just want to write random text to the page, you can use
HttpContext.Current.Response.Write("Hello World");
There are sometimes issues with Response.Write but it should be okay for what you want to do here.
Use breakpoints. Set a breakpoint at the end of your method by clicking in the "gutter" area. A red circle will appear that looks like this:
Now run your program in debug mode by clicking the button with the green triangle or pressing F5. The program will run, producing the output in the console (a separate window). Once it hits your breakpoint, you can examine the console for the output, like this:
You are reading a tutorial for Console Application, however you are trying to create a ASP.NET application. I would reccomend reading a tutorial for ASP.NET
Like many before said: it goes by too fast, so either use breakpoints, or use a Read...
You can also write to your Visual Studio output window with System.Diagnostics.Debug.Write
you need to put break point over the line which you want to debug
short cut to placing break point is ctrl D,n
then you can step over or step into the code with f10 and f11 function keys

How to start a program using a hotkey in C#?

I'm making a program using C#, the user should be blind person. I've done everything but I remembered that the blind user can't start the application like any person.
So is it possible in C# to add the program to the startup programs list and send it to the tray, and when the user presses Esc key for example, the program starts.
Thanks..
It's can be done without any connection to c#, follow this instructions:
http://windows.microsoft.com/en-US/windows-vista/Create-keyboard-shortcuts-to-open-programs?SignedIn=1
or tutorial:
http://www.butterscotch.com/tutorial/Launch-A-Program-With-Windows-Hotkeys

Categories

Resources