How to do simple game console in OpenGL using C#? - c#

I need to do simple game console - like from Quake, Counter-Strike or other games for simple 3D game using openGL and C#.
Just press button for example ~ and it will show the console.
I can write my commands in it and it will have effect on my application.
For example it will change value of some variable or call some method from my application.
Console should be in left top corner of the window. It's just window application(no full screen).
Have somebody any idea how to do it? Piece of code - how to draw the the console or some tutorial?
Thanks a lot.

Text Editing is difficult in Open GL. It isn't something you want to start off with. C# has text fields and rich text windows. The simplest way would be to create a Window with a TextField inside it in C#. When the user pressed ~ slide the window in and give it focus. When the user presses enter any text in the field is captured, the field is cleared, and the captured text is sent off to the game to be processed.
To give the full console feel you want to make re-print that entered text back out in. You can do that with another, non-editable text field above the first on. Just concat the recently entered string on the end of text already entered in that field.
I would not recommend starting with this. Get something on the screen, get it responding to the keyboard directly. Then worry about how you are going to have you debug data entered. For now you can just hardcode debug commands to random keys that you don't user for your control scheme.

Related

Draw rectangular selection and get corresponding image in WPF c#

I need to write a text recognition (from image) application. The main idea is that while my application is running, I may have the need to transform some text of an image into manageble text. So, in this case with the mouse I need to draw a square around the area that i need to capture and the software must convert the content of the extracted picture into text.
I solved the problem of image recognition. I also find a very easy way to capture from screen.
What I need to do now is be able to select with the mouse the interesting area that is over an other running opplication (for example over a webpage or over an image opened in Paint). That must be like the screencapture on windows7, you create a selection of the screen and this is saved like a picture.
By looking around, I didn't find anything and I don't knwo where to start.
Many thanks
You can achieve that using either a 'tricky' easy way or a real but difficult approach.
The tricky way
Screen Recorder applications usually use this approach:
Whenever user wants to select an area, you display a full screen border less Window with 0% opacity, then user attempts to select the screen area, and he is actually selecting your Window area, so you can receive mouse events and display/draw a rectangular shape to show the selection area to the user.
In this approach, the program needs to know when to display the Window and when to hide it. This can be done by for example defining Hotkeys for capturing:
Program registers a hot key using RegisterHotKey to Windows.
User presses and holds that hot key
Program displays the tricky Window
User selects the interested area, program receives that area using mouse events of the tricky Window
User released the hot key and program hides the Tricky window.
The real way
Using this way, you need to set a message hook in order to receive mouse and keyboard events while user is interacting with desktop not your program. This is not an easy to accomplish approach and I recommend you the first one.

How to paste text into a different application with C#

Here is my scenario:
A user has two applications open. Let's say one application is Notepad with some text in it and the other one is my C# application.
A user now positions the mouse cursor somewhere inside the Notepad text and then clicks a button in my C# application. As a result, a text string from my application gets pasted in Notepad where the cursor was positioned.
My question is: what would a general approach be to accomplish the above, and possibly what classes etc. are recommended?
I would look into using interop calls to accomplish this. Look at specifically GetWindow() and SendMessage with the WM commands (http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927(v=vs.85).aspx#system_defined) and GetDesktop().
GetDesktop will allow you to obtain all of the top level child windows of the desktop (all top level windows are children of the Desktop window).
You should then be able to use GetWindow to obtain the window handle you are looking for and then SendMessage to set the text into the textbox.

How to capture keystrokes before the foreground window gets it?

I'm doing an application like Google Transliteration (Google input tools) tool in C#. It displays the suggestion window on the top of whatever window we are typing (finds caret location & display just window below it). But the focus (foreground process) is still on the application in which we type (for eg. Ms Word, Notepad etc.).
I want to implement these features of Google Transliteration:
It captures the keystrokes before another process gets it.
While renaming a folder or file, we can select words from the suggestions
window show up by using up & down arrow keys and press enter key. But the
rename text field will be still active. The keystrokes will be
captured before it reaches rename text field.
I want to implement a universal text suggestion list (window) like that of Google Transliteration.
How to capture keystrokes before another process gets it (block foreground process from getting it)? (Main Question)
How to capture keystrokes (up & down arrow keys and enter key) and select an option from the words list without focusing on the 'words list' window?
(Caret should remain active and blinking on the foreground process text field. eg. Folder rename text field)
Someone please help me to solve this problem.
I already found this one, but it not helped me to solve my problem.
Capturing keystrokes without focus
You mix two different problems. The first problem - to catch keyboard input - nothing to do with the second - to make an unfocusable window.
The solution to the first problem is very simple - as stated in your link, there is no other way to do it other than Low-Level windows hooks.
The second problem is more difficult, the solution may require a little experimentation, creativity and knowledge of WinAPI. Examples are here, here and here.

Desktop Development : Remember Target After Losing Focus

Is it possible to take focus from another program to respond to an event, but then once the response has been handled, switch back to the previous program and restore the cursor where it was?
This sounds like a weird question, but think of it along the lines of
User is typing in a text box in Program A.
A window for Program B pops up and user presses a few buttons to confirm something.
Program B returns control to Program A and restores the selection of the textbox.
If there is a complete C# solution, then great, but this sounds like it might require a little more effort than usual.
Any thoughts?
Personally, doing this could very likely result in the user selecting undesired values in the popup window. For example, someone is typing away in Word. Your application pops up a window, where hitting "Enter" selects a value ... such as the default button. Without wanting to, the user "selected" an incorrect value on your form.
Windows itself tends to do this, and it's very annoying. Quickly double-clicking a desktop shortcut to open an application and then switching back to (for example) an e-mail before the app launches, will tend to remove focus from the focused e-mail window and put focus in the just-opened application, causing your e-mail text or keyboard strokes to go to the just-opened window.
In my experience windows programs work just this way. It often appears that they don't because the user is returning focus with a mouse-click, which itself resets the focus. If it's a winforms app you can probably do something with the lost focus/got focus events at the form level.

How to get text clicked from another program into your own textbox?

What I mean is how can I get text from another running active window. For example I have a program let's say word or msn. I am chatting with someone while my own program is running in the tray. I want to set a key let's say right click and ctrl to open up my program and get the word I clicked on.
I am using C#.
I direct you to my answer to the question Unified way to scrape HTML from any type of browser process
The answer links to an article on Coding the Wheel which details how to access text in other windows via system dll hooks. That should have what you require.
you could copy the word and then get the word out of the clip board in your application... otherwise your talking API's for any application you might was to get a word from.

Categories

Resources