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

Source: Internet
Author: User

As in the previous chapter, the calculator, to the last section, we always have to make the code neat, so that the whole program is very concise, first make a folder to put our custom class library in the

?

Then we began to tidy up the code inside the Form1, in order to implement the Super hotkey function, we should perfect the Functionmousekeyboardhook this class (because now called Super Hotkey, maybe we need to use the mouse keyboard to trigger to do some other things, Then if you can also take the code directly to the transplant will be very meaningful, do not change the framework of the business, the win+a/z letter should be enough, and consider not with the system's own shortcut key conflicts, such as Win+l is the system comes with the lock calculator, then in addition to the people we transplanted the sample code of the object, We also need to add additional objects (these are all moved from the Form1)

?

method is the same, from the Form1 directly to move over, in fact, is two aspects, one is the trigger of the mouse keyboard, one is the configuration file read and write

?

The benefit of this is obvious, Form1 is very clean, just reference the class library, and then initialized with a line, and then click the button is the text box data collection to perform read and write, and all the functions are in the class interaction. This is handy for porting and scaling, and why it's so much easier to do it in Form1 (all in the same way, but it's not good for scaling, we need to make the program as concise as possible)

?

For the monitoring of the mouse keyboard, we just refresh the Functionhook static property in the delegate, and then Form1 do a timer every 100ms refresh to get. This is done for ease of debugging because displaying the current mouse keyboard action in the label is no longer possible, we can fully implement the function we want, but keeping these is clear to know how our event was triggered and whether it was triggered.

?

For the read-write file part, we also made additional judgments, which is also a simple programming technique (a bool value of true, a few sets of shortcuts as long as there is an incorrect, one will not execute), and the entire function is not void but bool, That is, the form in the call to our class is able to know that the completion of no, if not completed, do not refresh the interface of the control (such as you write an illegal value, is clearly wrong, but the text box is still written in, this way can improve the quality of the code)

?

On the basis of this well-packaged class, let's simply refine it, for example, to make the previously read and write parameters into a form that can be imported and exported, the simplest way is to use C # 's own controls.

parameter import, essentially a dialog box to open a file (find a file and open it, get the full path and filename of the file OpenFileDialog in my custom class, already can fool to set up an initial directory, set the file type can (general initial directory settings in the root directory of the program, the file type is set to normal, the reader can see for themselves there is no other way, such as the way the C # comes with a control how to implement)

?

parameter export, essentially a dialog box to save the file (set a file name and save it, get the full path and file name SaveFileDialog in my custom class, already can fool to set up an initial directory, set the file type can (general initial directory settings in the root directory of the program, the file type is set to normal, the reader can see for themselves there is no other way, such as the way the C # comes with a control how to implement)

?

Finally see how to open the folder, because the search comes with the screenshot will be in his EXE in the same directory to generate a pool folder (this is his death, can not be changed) we just find this exe directory to open the pool directory (open folder is also a very common feature, Put under the Functionsystem class will be used often)

?

Finally, in order to compare the TXT and INI read and write, I also put the INI read and write simple implementation (INI than txt is more canonical, section is a node, key is the name, value is a value, you can have multiple nodes, each node has more than one key, Each key corresponding to a value can be, interested readers can improve themselves (if you want to enumerate the read and write files, but also a lot of, Xml,xls, database are, and each has advantages and disadvantages, beginners master one or two kinds of common can)

?

Summary: This lesson is still relatively long, because we have expanded a lot of custom classes (functionsystem,functionstring), each class will later in the actual project to improve programming efficiency, reduce garbage code, Readers still need to carefully understand the code is how to modify the steps to a simple enough (in fact, this super hotkey can still be extended, to do more practical, such as the boot automatically start, minimize the tray icon, or with our previous section of the calculator written, a shortcut to open the calculator, the reader can play freely).

1 understand how to use other people's classes, quickly understand other people's entire process from control to implementation, can transplant others ' code themselves

2 Learn to build some of their own, expand some of the features (such as the code in other people just can capture the mouse keyboard, then capture the combination of keys is to find a way to achieve)

3 Learn to expand their own libraries, especially with systems such as file processing, system time, System hardware, system memory consumption, which we all might use, dealing with strings (import and export of variables, etc.)

?

?

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.3 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.