C # Basic Video tutorial 5.2 How to write a simple super hotkey

Source: Internet
Author: User

We have already understood how to use the official code to implement the mouse keyboard monitoring, in fact, it is very close, because his code can only capture a single button, but in fact we want to be a combination of keys. What are key combinations? For example I want to define simultaneous press Win+c to go to the execution screen. As long as it is understood that the win key is pressed and does not bounce, the C key is also pressed, and then to execute an EXE program.

?

We need to write a class to wrap up the previous package

?

This is relatively concise, the initialization and the addition of binding are only one row (+ = is the addition of bindings, the reader can also test multiple + = effect,-= is to unbind, so that the main program will appear relatively clean)

?

Let's think about how to implement capturing a set of keys, such as the win key is the first to touch the Heat key, C is the second hot button, trigger after the execution of Capturescreen (screen screenshot), if D is the second hot key, do drawscreen (screen drawing), So it is clear that the first step is to write a trigger method, if the Hotkeymain is set up, and then see whether the second button is set up, if it is set up to perform the specified function

?

At the time of initialization, we have specified that Hotkeymain is a A-Z of the 26 letters (we do not consider the more complex case, such as the F1-f12 button, such as tab, special symbol as the trigger button of the hotkey)

?

After detecting that the win key is released, the first Boolean value is already false and no more functions will be triggered (this is, of course, the logical way of thinking that the reader can think there is no more reasonable way, and we will migrate these to the new custom class in the next section, Form1. Separating the presentation layer and the business layer of the program so that we could expand our own class library.

?

Specific to the implementation level, we only need to call the Windows bring the Process class (put three EXE files in the Debug directory), as for the three exe how to get the first stop (there are many online, such as Capturescreen this EXE tool is the Sogou comes with, We take directly to use can), because finally I generated EXE program is also debug directory packaging can, so here for convenience directly into the same directory can, process. Startinfo.filename do not need to follow the detailed path

?

In order to allow users to customize the shortcut keys, we can also make a combination of letters to read and write the way (can load files, can also write files), the most common way to read and write files is definitely a TXT file (I also provide the INI file read and write class, will read and write Excel, read and write data, etc., First, the simplest). First we test the method of writing the file, here we have added two classes, one is Functionsystem (get the system commonly used directory), one is Functionfiletxt (execute TXT file read and write), these functions can be easily found Baidu, We just want to illustrate the benefits of integrating into our own classes, which can be called directly

?

Here for the time being do not explain the notes of reading and writing files, there are many patterns, many parameters, but in fact, we will only need to consider a few common (append or rewrite), here we just write the three line shortcut key corresponding information

?

and get the System folder function Functionsystem We will continue to expand in the future (because in addition to the quick positioning to the common directory such as programs files folder, Windows folder, the directory of the program, this class should have a lot of other functions, we will expand later)

?

After writing the file implementation, the next step is to consider reading (why xxx| C,xxx| What about d? This is our own definition, because the format is set by itself, the middle of your split symbol can also be a space or other characters, or you can not use my line to a parameter of the way, I will then read and parse the file I just wrote (to carefully understand the file read and write process, is not the specific code to read and write, because the Web can find a lot of copy on the line, but why read and write so, how to save the variable in the simplest format)

?

With the read and write, reset is very simple, is to write the default parameters (you can directly copy a write, the original variable is a constant)

?

When reading the file we also introduced the parsing of the string (just to extract the string into a string array or directly into a set of floating-point numbers), this is also temporarily do not need to fully grasp, simple have escaped characters, complex have regular expressions, are enough to learn a week, but in most cases, as long as you can find, Can take other people's use on it, we will continue to improve the functionstring this class (first to the entire configuration file by \ n Extract to the row, and then on each row by the | split into a string, extract each line of | After the string), there is actually a lot of work to do, For example, when the program just loaded, read parameters, such as the user input custom parameters to restrict, prevent illegal input and so on, we will be described in the following section.

?

?

For more instructional videos and downloads, please pay attention to the following information:

My Youku Space:

Http://i.youku.com/acetaohai123

?

My online forum:

http://csrobot.gz01.bdysite.com/

?

Problem Exchange:

qq:910358960

Email:[email protected]

?

?

?

C # Basic Video tutorial 5.2 How to write a simple super hotkey

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.