Need an example about console application which user can interact console window - c#

I need write a console application like as hiren boot screen:
alt text http://xahoithongtin.com.vn/Images/diembao/2006_10/Hiren2.jpg
User can input a arrow key or a number for choosing. When a menu item is selected, I will fill a background for the selected menu item.
Please give me some guideline or example. Thanks.

The console class has all the core functionality you need.
To set the cursor to any desired position you can use the Console.CursorLeft or Console.CursorTop properties. A little example is already posted here.
For the colors you can use the Console.BackgroundColor and Console.ForegroundColor.
With these properties you should be able to write all this stuff onto the screen. Afterwards you need to check the user input (KeyUp, KeyDown pressed). This can be done by checking the result of Console.ReadKey() method. By setting the boolean paramter to true you can prevent that the pressed character is displayed on the screen itself.
With this base functionality you should be able to write your own helper class to make all this stuff a little more comfortable.

There are several .NET based NCurses libraries around that make creation of console based interfaces easier:
Curses#
MonoCurses
CursesSharp

Related

Go back to the main menu at any point during a method

If the user is in the middle of adding a Customer, they may decide that they want to go back for whatever reason. When the user is entering new details, I want them to be able to press the "Esc" button at any point to go back to the main menu. I've already implemented it in my application where the user can select a number from a menu, but that's only when they reach a certain point within the program. can anyone help?
I would suggest encapsulating all of your prompts and reading input as one method that takes parameters.
public static string PromptUserForInput(string promptMessage, bool checkForEscape = true){...}
Then use the readkey like #h0r53 said. I was going to build out a basic example, but it looks like one can already be found here. Then just tweak as needed.

perform a hotkey when press a graphical button

I got a thought experiment with a graphical user interface for writing a command.
There are buttons for saving, writing cursive and so on.....
Now when i press the button save, i want to that the compiler perform Ctrl+S like in every textdocument, or change the marked one to cursive with Ctrl+Shift+K.
I tried to set the variable to the value of the ascii code, but this ainĀ“t worked. Now i need help that the compiler perform the hotkey.
Is there a function in C# or is there another way to realize that.
Actually those hotkeys are implemented functions of the programs you use (e.g. word). The hotkey just executes the same function as the button you can press - the compiler doesn't know the hotkey Ctrl+Shift+K.
Just think about it: If the compiler knew about those hotkeys, it would have to know how to make the selected text in the focused textbox cursive - wouldn't this be kind of strange?
I might misunderstand your question, maybe you just wanted to ask how to type text with a simulated keyboard for the form, because you already implemented the shortcut functionability. In that case you'd have two options:
Call the function called when you press the specified shortcut
Actually simulate keypresses to the form
The second one is done like that:
SendKeys.Send("^S"); //For Ctrl+S - ^ is the Control button
For other special keys with the SendKeys function take a look at this: https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx.

How do I force selection of a keyboard type in a Xamarin.Webkit.Webview

We have a Xamarin app (Android) that at one stage opens up a web view (Webkit.Webview not Forms.Webview). This directs the user to a page on a third party site which has been set up for us.
Firstly - on certain input fields the keyboard which shows up is the wrong one - we are expecting a dismissable keyboard (i.e. "Done" in the bottom corner, not a "Submit"). I know this can be changed but not sure what is the correct way to do this. Does it have to be the metadata/text inputs on the web page that is changed? If so - what needs to be modified per text box entry on the html of the page? Just the type? i.e:
<input type="email">
Secondly, rather than wait for the third party to fix the page, is there a way we can force the webview to always open a certain keyboard type?
We have an option of intercepting the keyboard key presses and trying to dismiss the keyboard on return press at the minute. But would prefer not to put a hack in that intercepts every key press.
Appreciate the help, not sure what the way forward is here.
Thanks
From the comments: To your second question about forcing a keyboard button, you can check out this link which describes how to override OnCreateInputConnection to specify the Keyboard Enter Button type.
public class MyWebView : WebView {
...
public override IInputConnection OnCreateInputConnection (EditorInfo outAttrs) {
var inputConnection = base.OnCreateInputConnection (outAttrs);
// outAttrs.ImeOptions in Xamarin only allows ImeFlags but it also should allow ImeActions
outAttrs.ImeOptions = outAttrs.ImeOptions | (ImeFlags)ImeAction.Next;
return inputConnection;
}
}
That will not dismiss your keyboard when tapped though since it is meant to take the user to the next input. Hopefully someone else can come along and either provide a better answer or give a good way to dismiss the keyboard in this situation without hacking something together.

Button with no hWnd

Good evening folks,
I'm building a simple application (A) that sends Strings to a textbox of another application (B). I was able to this step, but afterwards I'd like to automatically press a button placed just under the textbox. The problem is that I can't get the Handle of the Button; using "Window Detective"(similiar to Spy++), I see only the textboxes (called "TEdit", see the attachments) and no Buttons!. I'd like to add also that there's no only a Button but 3!! So, how could I press a specific Button? Is there another chance to get the Handle?
Program "target"
Window Detective screenshot
Based on the class name TEdit that's a VCL application probably coded in Delphi. The buttons are likely TSpeedButton and non-windowed. You won't be able to send them messages and they are not automatable.
Faced with this your best hope of success is to fake input. Fake the mouse click at the appropriate location on the form. It's not pretty but there's little option.

count any keystrokes whether or not Window (App) is in focus - WPF

I'm building a "WPF Application" which is made to be run in the background (minimised state) and detects KeyStrokes of each and Every key on the keyboard & every Mouse Clicks.
So, my question is how to detect every keyStrokes whether app (Window) is minimised or not.
Simply, if my app is in focus then i use this code to count keystrokes.
Public int count;
protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e)
{
//base.OnKeyDown(e);
count++;
tBlockCount.Text = count.ToString();
}
I just want to do the same even if my app is minimised.
I've searched a lot and come across many suggestions like..
http://www.pinvoke.net/default.aspx/user32/registerhotkey.html
http://social.msdn.microsoft.com/Forums/vstudio/en-US/87d66b1c-330c-42fe-8a40-81f82012575c/background-hotkeys-wpf?forum=wpf
Detecting input keystroke during WPF processing
Detect if any key is pressed in C# (not A, B, but any)
Most of those are indicating towards Registering HotKeys. But I'm unable to match scenario with mine.
Any kind of suggestion are most welcome.
Although I'm not really condoning the use of a keylogger (This is what you are trying to do). I would recommend taking a look at this q/a, the section near the bottom of this article, and this article for some inspiration. These should help point in the right direction for the coding side.
What you essentially need to do is just set up an event to intercept any keys that come in from the computer, then you can gather the key and do whatever you like with it (in your case, record it)
Edit: In fact, reading the third article, it actually gives a full code snippet on how to implement and use it in WPF, so I recommend just reading that one.

Categories