├── LICENSE ├── README.md ├── dmfile.py ├── dminput.py ├── dmpic.py ├── dmsystem.py └── dmwindow.py /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DMProject 2 | 用最少的依赖实现python版大漠插件(大漠插件v7.1904帮助文档:https://lanzous.com/icguueh) 3 | * 一切开发旨在学习,请勿用于非法用途 4 | ## API实现情况 5 | ### 系统(dmsystem.py) 6 | * [x] Beep 蜂鸣器 7 | * [x] CheckFontSmooth 检测当前系统是否有开启屏幕字体平滑. 8 | * [x] CheckUAC 检测当前系统是否有开启UAC. 9 | * [x] Delay 延时指定的毫秒,过程中不阻塞UI操作. 一般高级语言使用.按键用不到.(实现不完整) 10 | * [x] Delays 延时指定范围内随机毫秒,过程中不阻塞UI操作. 一般高级语言使用.按键用不到.(实现不完整) 11 | * [x] DisableCloseDisplayAndSleep 设置当前的电源设置,禁止关闭显示器,禁止关闭硬盘,禁止睡眠,禁止待机. 不支持XP. 12 | * [x] DisableFontSmooth 关闭当前系统屏幕字体平滑.同时关闭系统的ClearType功能. 13 | * [x] DisablePowerSave 关闭电源管理,不会进入睡眠. 14 | * [x] DisableScreenSave 关闭屏幕保护. 15 | * [x] EnableFontSmooth 开启当前系统屏幕字体平滑.同时开启系统的ClearType功能. 16 | * [x] ExitOs 注销、重启、关机 17 | * [x] GetClipboard 获取剪贴板的内容 18 | * [x] GetCpuType 获取当前CPU类型,intel或者amd. 19 | * [x] GetDir 得到系统的路径 20 | * [x] GetDiskSerial 获取本机的硬盘序列号.支持ide scsi硬盘. 要求调用进程必须有管理员权限. 否则返回空串. 21 | * [ ] GetDisplayInfo 获取本机的显卡信息.(暂不实现) 22 | * [x] GetDPI 判断当前系统的DPI(文字缩放)是不是100%缩放. 23 | * [ ] GetLocale 判断当前系统使用的非UNICODE字符集是否是GB2312(暂不实现) 24 | * [ ] GetMachineCode 获取本机的机器码.(带网卡). 此机器码用于插件网站后台. (暂不实现) 25 | * [x] GetMachineCodeNoMac 获取本机的机器码.(不带网卡)(实现不完整) 26 | * [x] GetNetTime 从网络获取当前北京时间. 27 | * [x] GetNetTimeByIp 根据指定时间服务器IP,从网络获取当前北京时间. 28 | * [x] GetNetTimeSafe 请使用GetNetTimeByIp代替 29 | * [x] GetOsBuildNumber 得到操作系统的build版本号. 比如win10 16299,那么返回的就是16299. 其他类似. 30 | * [x] GetOsType 得到操作系统的类型. 31 | * [x] GetScreenDepth 获取屏幕的色深. 32 | * [x] GetScreenHeight 获取屏幕的高度. 33 | * [x] GetScreenWidth 获取屏幕的宽度. 34 | * [x] GetTime 获取当前系统从开机到现在所经历过的时间,单位是毫秒. 35 | * [x] Is64Bit 判断当前系统是否是64位操作系统 36 | * [x] Play 播放指定的MP3或者wav文件. 37 | * [x] RunApp 运行指定的应用程序.(实现不完整) 38 | * [x] SetClipboard 设置剪贴板的内容 39 | * [ ] SetDisplayAcceler 设置当前系统的硬件加速级别.(暂不实现) 40 | * [ ] SetLocale 设置当前系统的非UNICOD字符集.(暂不实现) 41 | * [x] SetScreen 设置系统的分辨率 系统色深 42 | * [x] SetUAC 设置当前系统的UAC,重启生效. 43 | * [x] ShowTaskBarIcon 显示或者隐藏指定窗口在任务栏的图标. 44 | * [x] Stop 停止指定的音乐. 45 | ### 文件(dmfile.py) 46 | * [x] CopyFile 拷贝文件. 47 | * [x] CreateFolder 创建指定目录. 48 | * [ ] DecodeFile 解密指定的文件. 49 | * [x] DeleteFile 删除文件. 50 | * [x] DeleteFolder 删除指定目录. 51 | * [ ] DeleteIni 删除指定的ini小节. 52 | * [ ] DeleteIniPwd 删除指定的ini小节.支持加密文件 53 | * [x] DownloadFile 从internet上下载一个文件. 54 | * [ ] EncodeFile 加密指定的文件. 55 | * [ ] EnumIniKey 根据指定的ini文件以及section,枚举此section中所有的key名 56 | * [ ] EnumIniKeyPwd 根据指定的ini文件以及section,枚举此section中所有的key名.可支持加密文件 57 | * [ ] EnumIniSection 根据指定的ini文件,枚举此ini中所有的Section(小节名) 58 | * [ ] EnumIniSectionPwd 根据指定的ini文件,枚举此ini中所有的Section(小节名) 可支持加密文件 59 | * [x] GetFileLength 获取指定的文件长度. 60 | * [ ] GetRealPath 获取指定文件或目录的真实路径 61 | * [x] IsFileExist 判断指定文件是否存在. 62 | * [x] IsFolderExist 判断指定目录是否存在. 63 | * [x] MoveFile 移动文件. 64 | * [x] ReadFile 从指定的文件读取内容. 65 | * [ ] ReadIni 从Ini中读取指定信息. 66 | * [ ] ReadIniPwd 从Ini中读取指定信息.可支持加密文件 67 | * [x] SelectDirectory 弹出选择文件夹对话框,并返回选择的文件夹. 68 | * [x] SelectFile 弹出选择文件对话框,并返回选择的文件. 69 | * [x] WriteFile 向指定文件追加字符串. 70 | * [ ] WriteIni 向指定的Ini写入信息. 71 | * [ ] WriteIniPwd 向指定的Ini写入信息.支持加密文件 72 | ### 键鼠(dminput.py) 73 | * [x] EnableMouseAccuracy 设置当前系统鼠 标的精确度开关. 如果所示。 此接口仅仅对MoveR接口起作用. 74 | * [x] GetCursorPos 获取鼠标位置. 75 | * [x] GetCursorShape 获取鼠标特征码. 76 | * [x] GetCursorShapeEx 获取鼠标特征码.(实现不完整) 77 | * [x] GetCursorSpot 获取鼠标热点位置.(实现不完整) 78 | * [x] GetKeyState 获取指定的按键状态. 79 | * [x] GetMouseSpeed 获取系统鼠标的移动速度. 80 | * [x] KeyDown 按住指定的虚拟键码 81 | * [x] KeyDownChar 按住指定的虚拟键码 82 | * [x] KeyPress 按下指定的虚拟键码 83 | * [x] KeyPressChar 按下指定的虚拟键码 84 | * [x] KeyPressStr 根据指定的字符串序列,依次按顺序按下其中的字符. 85 | * [x] KeyUp 弹起来虚拟键vk_code 86 | * [x] KeyUpChar 弹起来虚拟键vk_code 87 | * [x] LeftClick 按下鼠标左键 88 | * [x] LeftDoubleClick 双击鼠标左键 89 | * [x] LeftDown 按住鼠标左键 90 | * [x] LeftUp 弹起鼠标左键 91 | * [x] MiddleClick 按下鼠标中键 92 | * [x] MiddleDown 按住鼠标中键 93 | * [x] MiddleUp 弹起鼠标中键 94 | * [x] MoveR 鼠标相对于上次的位置移动rx,ry. 95 | * [x] MoveTo 把鼠标移动到目的点(x,y) 96 | * [x] MoveToEx 把鼠标移动到目的范围内的任意一点 97 | * [x] RightClick 按下鼠标右键 98 | * [x] RightDown 按住鼠标右键 99 | * [x] RightUp 弹起鼠标右键 100 | * [ ] SetKeypadDelay 设置按键时,键盘按下和弹起的时间间隔。(暂不支持) 101 | * [ ] SetMouseDelay 设置鼠标单击或者双击时,鼠标按下和弹起的时间间隔。(暂不支持) 102 | * [x] SetMouseSpeed 设置系统鼠标的移动速度. 103 | * [ ] SetSimMode 设置前台键鼠的模拟方式.(暂不支持) 104 | * [x] WaitKey 等待指定的按键按下 (前台,不是后台) 105 | * [x] WheelDown 滚轮向下滚 106 | * [x] WheelUp 滚轮向上滚 107 | ### 窗口 108 | * [x] ClientToScreen 把窗口坐标转换为屏幕坐标 109 | * [x] EnumProcess 根据指定进程名,枚举系统中符合条件的进程PID,并且按照进程打开顺序排序. 110 | * [x] EnumWindow 根据指定条件,枚举系统中符合条件的窗口(实现不完整) 111 | * [ ] EnumWindowByProcess 根据指定进程以及其它条件,枚举系统中符合条件的窗口 112 | * [ ] EnumWindowByProcessId 根据指定进程pid以及其它条件,枚举系统中符合条件的窗口 113 | * [ ] EnumWindowSuper 根据两组设定条件来枚举指定窗口. 114 | * [x] FindWindow 查找符合类名或者标题名的顶层可见窗口 115 | * [x] FindWindowByProcess 根据指定的进程名字,来查找可见窗口. 116 | * [x] FindWindowByProcessId 根据指定的进程Id,来查找可见窗口. 117 | * [x] FindWindowEx 查找符合类名或者标题名的顶层可见窗口,如果指定了parent,则在parent的第一层子窗口中查找. 118 | * [ ] FindWindowSuper 根据两组设定条件来查找指定窗口. 119 | * [x] GetClientRect 获取窗口客户区域在屏幕上的位置 120 | * [x] GetClientSize 获取窗口客户区域的宽度和高度 121 | * [x] GetForegroundFocus 获取顶层活动窗口中具有输入焦点的窗口句柄 122 | * [x] GetForegroundWindow 获取顶层活动窗口 123 | * [x] GetMousePointWindow 获取鼠标指向的可见窗口句柄 124 | * [x] GetPointWindow 获取给定坐标的可见窗口句柄 125 | * [x] GetProcessInfo 根据指定的pid获取进程详细信息,(进程名,进程全路径,CPU占用率(百分比),内存占用量(字节)) 126 | * [x] GetSpecialWindow 获取特殊窗口 127 | * [x] GetWindow 获取给定窗口相关的窗口句柄 128 | * [x] GetWindowClass 获取窗口的类名 129 | * [x] GetWindowProcessId 获取指定窗口所在的进程ID. 130 | * [x] GetWindowProcessPath 获取指定窗口所在的进程的exe文件全路径. 131 | * [x] GetWindowRect 获取窗口在屏幕上的位置 132 | * [x] GetWindowState 获取指定窗口的一些属性 133 | * [x] GetWindowTitle 获取窗口的标题 134 | * [x] MoveWindow 移动指定窗口到指定位置 135 | * [x] ScreenToClient 把屏幕坐标转换为窗口坐标 136 | * [x] SendPaste 向指定窗口发送粘贴命令. 把剪贴板的内容发送到目标窗口. 137 | * [ ] SendString 向指定窗口发送文本数据 138 | * [ ] SendString2 向指定窗口发送文本数据 139 | * [ ] SendStringIme 向绑定的窗口发送文本数据.必须配合dx.public.input.ime属性. 140 | * [ ] SendStringIme2 利用真实的输入法,对指定的窗口输入文字. 141 | * [x] SetClientSize 设置窗口客户区域的宽度和高度 142 | * [x] SetWindowSize 设置窗口的大小 143 | * [x] SetWindowState 设置窗口的状态(实现不完整) 144 | * [x] SetWindowText 设置窗口的标题 145 | * [x] SetWindowTransparent 设置窗口的透明度 146 | ### 内存 147 | ### 图色 148 | ### (待定) 149 | 150 | -------------------------------------------------------------------------------- /dmfile.py: -------------------------------------------------------------------------------- 1 | ''' 2 | /* 3 | * Copyright 2020 DMProject and contributors. 4 | * 5 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 6 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 7 | * 8 | * https://github.com/super1207/DMProject/blob/master/LICENSE 9 | */ 10 | ''' 11 | 12 | ''' 13 | @Description: 大漠插件7.1904[文件]API部分的python实现 14 | @FilePath: dmfile.py 15 | ''' 16 | 17 | import shutil 18 | import os 19 | import urllib.request 20 | import tkinter 21 | import tkinter.filedialog 22 | 23 | 24 | class DMFile(): 25 | # winKernel32 = ctypes.windll.kernel32 26 | # winuser32 = ctypes.windll.LoadLibrary('user32.dll') 27 | # wingdi32 = ctypes.windll.LoadLibrary('gdi32.dll') 28 | # winntdll = ctypes.windll.LoadLibrary('ntdll.dll') 29 | # winwinmm = ctypes.windll.LoadLibrary('winmm.dll') 30 | @staticmethod 31 | def CopyFile(src_file,dst_file,over)->None: 32 | if over: 33 | shutil.copyfile(src_file, dst_file) 34 | else: 35 | if not IsFileExist(dst_file): 36 | shutil.copyfile(src_file, dst_file) 37 | @staticmethod 38 | def CreateFolder(folder)->None: 39 | os.makedirs(folder) 40 | @staticmethod 41 | def DeleteFile(file)->None: 42 | os.remove(file) 43 | @staticmethod 44 | def DeleteFolder(folder)->None: 45 | os.removedirs(folder) 46 | @staticmethod 47 | def DownloadFile(url,save_file,timeout)->None: 48 | urllib.request.urlretrieve(url, save_file,timeout = timeout / 1000) 49 | @staticmethod 50 | def GetFileLength(file) -> int: 51 | return os.path.getsize(file) 52 | @staticmethod 53 | def IsFileExist(file) -> bool: 54 | return os.path.isfile(file) 55 | @staticmethod 56 | def IsFolderExist(folder) ->bool: 57 | return os.path.isdir(folder) 58 | @staticmethod 59 | def MoveFile(src_file,dst_file) -> None: 60 | shutil.move(src_file,dst_file) 61 | @staticmethod 62 | def ReadFile(file) -> str: 63 | with open(file,'r',encoding='GB2312') as f: 64 | return f.read() 65 | @staticmethod 66 | def SelectDirectory() ->str: 67 | root = tkinter.Tk() 68 | root.withdraw() 69 | return tkinter.filedialog.askdirectory() 70 | @staticmethod 71 | def SelectFile() -> str: 72 | root = tkinter.Tk() 73 | root.withdraw() 74 | return tkinter.filedialog.askopenfilename() 75 | @staticmethod 76 | def WriteFile(file,content) -> None: 77 | with open(file,'a',encoding="GB2312") as f: 78 | f.write(content) 79 | -------------------------------------------------------------------------------- /dminput.py: -------------------------------------------------------------------------------- 1 | ''' 2 | /* 3 | * Copyright 2020 DMProject and contributors. 4 | * 5 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 6 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 7 | * 8 | * https://github.com/super1207/DMProject/blob/master/LICENSE 9 | */ 10 | ''' 11 | 12 | ''' 13 | @Description: 大漠插件7.1904[键鼠]API部分的python实现 14 | @FilePath: dminput.py 15 | ''' 16 | 17 | import ctypes 18 | import ctypes.wintypes 19 | import time 20 | import random 21 | 22 | class DMInput(): 23 | winKernel32 = ctypes.windll.kernel32 24 | winuser32 = ctypes.windll.LoadLibrary('user32.dll') 25 | key_table = {"1":49, 26 | "2":50, 27 | "3":51, 28 | "4":52, 29 | "5":53, 30 | "6":54, 31 | "7":55, 32 | "8":56, 33 | "9":57, 34 | "0":48, 35 | "-":189, 36 | "=":187, 37 | "back":8, 38 | "a":65, 39 | "b":66, 40 | "c":67, 41 | "d":68, 42 | "e":69, 43 | "f":70, 44 | "g":71, 45 | "h":72, 46 | "i":73, 47 | "j":74, 48 | "k":75, 49 | "l":76, 50 | "m":77, 51 | "n":78, 52 | "o":79, 53 | "p":80, 54 | "q":81, 55 | "r":82, 56 | "s":83, 57 | "t":84, 58 | "u":85, 59 | "v":86, 60 | "w":87, 61 | "x":88, 62 | "y":89, 63 | "z":90, 64 | "ctrl":17, 65 | "alt":18, 66 | "shift":16, 67 | "win":91, 68 | "space":32, 69 | "cap":20, 70 | "tab":9, 71 | "~":192, 72 | "esc":27, 73 | "enter":13, 74 | "up":38, 75 | "down":40, 76 | "left":37, 77 | "right":39, 78 | "option":93, 79 | "print":44, 80 | "delete":46, 81 | "home":36, 82 | "end":35, 83 | "pgup":33, 84 | "pgdn":34, 85 | "f1":112, 86 | "f2":113, 87 | "f3":114, 88 | "f4":115, 89 | "f5":116, 90 | "f6":117, 91 | "f7":118, 92 | "f8":119, 93 | "f9":120, 94 | "f10":121, 95 | "f11":122, 96 | "f12":123, 97 | "[":219, 98 | "]":221, 99 | "\\":220, 100 | ";":186, 101 | "'":222, 102 | ":":188, 103 | ".":190, 104 | "/":191} 105 | 106 | 107 | @staticmethod 108 | def EnableMouseAccuracy(enable) -> bool: 109 | SPI_SETMOUSE = 0x0004 110 | SPI_GETMOUSE = 0x0003 111 | SPIF_SENDCHANGE = 0x0002 112 | aMouseInfo=(ctypes.c_uint32*3)(6,10,1) 113 | DMInput.winuser32.SystemParametersInfoA(SPI_GETMOUSE,0,ctypes.pointer(aMouseInfo),0) 114 | last = aMouseInfo[2] 115 | if enable: 116 | aMouseInfo=(ctypes.c_uint32*3)(6,10,1) 117 | else: 118 | aMouseInfo=(ctypes.c_uint32*3)(0,0,0) 119 | retnum = DMInput.winuser32.SystemParametersInfoA(SPI_SETMOUSE,0,ctypes.pointer(aMouseInfo),SPIF_SENDCHANGE) 120 | return last == 1 121 | @staticmethod 122 | def GetCursorPos() -> tuple: 123 | class POINT(ctypes.Structure): 124 | _fields_ = [ 125 | ("x",ctypes.wintypes.LONG), 126 | ("y",ctypes.wintypes.LONG) 127 | ] 128 | point = POINT() 129 | DMInput.winuser32.GetCursorPos(ctypes.byref(point)) 130 | return (point.x,point.y) 131 | @staticmethod 132 | def GetCursorShape() -> int: 133 | class POINT(ctypes.Structure): 134 | _fields_ = [ 135 | ("x",ctypes.wintypes.LONG), 136 | ("y",ctypes.wintypes.LONG) 137 | ] 138 | hCursor = None 139 | point = POINT() 140 | DMInput.winuser32.GetCursorPos(ctypes.byref(point)) 141 | hWnd = DMInput.winuser32.WindowFromPoint(point) 142 | dwThreadID = DMInput.winuser32.GetWindowThreadProcessId(hWnd, 0) 143 | dwCurrentThreadID = DMInput.winKernel32.GetCurrentThreadId() 144 | if dwCurrentThreadID != dwThreadID: 145 | if DMInput.winuser32.AttachThreadInput(dwCurrentThreadID, dwThreadID, True): 146 | hCursor = DMInput.winuser32.GetCursor() 147 | DMInput.winuser32.AttachThreadInput(dwCurrentThreadID, dwThreadID, False) 148 | else: 149 | hCursor = DMInput.winuser32.GetCursor() 150 | return hCursor 151 | @staticmethod 152 | def GetCursorShape(type_) -> int: 153 | return GetCursorShape() 154 | @staticmethod 155 | def GetCursorSpot() -> tuple: 156 | return GetCursorPos() 157 | @staticmethod 158 | def GetKeyState(vk_code) -> bool: 159 | return (DMInput.winuser32.GetKeyState(vk_code)>>15) == 1 160 | @staticmethod 161 | def GetMouseSpeed() -> int: 162 | SPI_GETMOUSESPEED = 0x0070 163 | speed = ctypes.c_int32() 164 | DMInput.winuser32.SystemParametersInfoA(SPI_GETMOUSESPEED,0,ctypes.pointer(speed),0) 165 | return int((speed.value+2)/2) 166 | @staticmethod 167 | def KeyDown(vk_code) -> None: 168 | DMInput.winuser32.keybd_event(vk_code,0,0,0) 169 | @staticmethod 170 | def KeyDownChar(key_str) -> None: 171 | DMInput.winuser32.keybd_event(DMInput.key_table[key_str],0,0,0) 172 | @staticmethod 173 | def KeyPress(vk_code) -> None: 174 | KEYEVENTF_KEYUP = 0x0002 175 | DMInput.winuser32.keybd_event(vk_code,0,0,0) 176 | DMInput.winuser32.keybd_event(vk_code,0,KEYEVENTF_KEYUP,0) 177 | @staticmethod 178 | def KeyPressChar(key_str) -> None: 179 | KEYEVENTF_KEYUP = 0x0002 180 | DMInput.winuser32.keybd_event(DMInput.key_table[key_str],0,0,0) 181 | DMInput.winuser32.keybd_event(DMInput.key_table[key_str],0,KEYEVENTF_KEYUP,0) 182 | @staticmethod 183 | def KeyPressStr(key_str,delay) -> None: 184 | for ch in key_str: 185 | DMInput.KeyPressChar(ch) 186 | time.sleep(delay/1000) 187 | @staticmethod 188 | def KeyUp(vk_code) -> None: 189 | KEYEVENTF_KEYUP = 0x0002 190 | DMInput.winuser32.keybd_event(vk_code,0,KEYEVENTF_KEYUP,0) 191 | @staticmethod 192 | def KeyUpChar(key_str) -> None: 193 | KEYEVENTF_KEYUP = 0x0002 194 | DMInput.winuser32.keybd_event(DMInput.key_table[key_str],0,KEYEVENTF_KEYUP,0) 195 | @staticmethod 196 | def LeftClick() -> None: 197 | DMInput.LeftDown() 198 | DMInput.LeftUp() 199 | @staticmethod 200 | def LeftDoubleClick() -> None: 201 | DMInput.LeftClick() 202 | time.sleep(0.01) 203 | DMInput.LeftClick() 204 | @staticmethod 205 | def LeftDown() -> None: 206 | MOUSEEVENTF_LEFTDOWN = 0x0002 207 | DMInput.winuser32.mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0) 208 | @staticmethod 209 | def LeftUp() -> None: 210 | MOUSEEVENTF_LEFTUP = 0x0004 211 | DMInput.winuser32.mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0) 212 | @staticmethod 213 | def MiddleClick() -> None: 214 | DMInput.MiddleDown() 215 | DMInput.MiddleUp() 216 | @staticmethod 217 | def MiddleDown() -> None: 218 | MOUSEEVENTF_MIDDLEDOWN = 0x0020 219 | DMInput.winuser32.mouse_event(MOUSEEVENTF_MIDDLEDOWN,0,0,0,0) 220 | @staticmethod 221 | def MiddleUp() -> None: 222 | MOUSEEVENTF_MIDDLEUP = 0x0040 223 | DMInput.winuser32.mouse_event(MOUSEEVENTF_MIDDLEUP,0,0,0,0) 224 | def MoveR(rx,ry) -> None: 225 | MOUSEEVENTF_MOVE = 0x0001 226 | DMInput.winuser32.mouse_event(MOUSEEVENTF_MOVE,rx,ry,0,0) 227 | def MoveTo(x,y) -> None: 228 | MOUSEEVENTF_MOVE = 0x0001 229 | MOUSEEVENTF_ABSOLUTE = 0x8000 230 | SM_CXSCREEN = 0 231 | SM_CYSCREEN = 1 232 | cx_screen = DMInput.winuser32.GetSystemMetrics(SM_CXSCREEN) 233 | cy_screen = DMInput.winuser32.GetSystemMetrics(SM_CYSCREEN) 234 | real_x = round(65535 * x / cx_screen) 235 | real_y = round(65535 * y / cy_screen) 236 | DMInput.winuser32.mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE,real_x,real_y,0,0) 237 | def MoveToEx(x,y,w,h) -> None: 238 | DMInput.MoveTo(x + random.randint(0,w),y + random.randint(0,h)) 239 | @staticmethod 240 | def RightClick() -> None: 241 | DMInput.RightDown() 242 | DMInput.RightUp() 243 | @staticmethod 244 | def RightDown() -> None: 245 | MOUSEEVENTF_RIGHTDOWN = 0x0008 246 | DMInput.winuser32.mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0) 247 | @staticmethod 248 | def RightUp() -> None: 249 | MOUSEEVENTF_RIGHTUP = 0x0010 250 | DMInput.winuser32.mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0) 251 | @staticmethod 252 | def SetMouseSpeed(speed) -> None: 253 | setspeed = ctypes.c_int32([0,1,2,4,6,8,10,12,14,16,18,20][speed]) 254 | DMInput.winuser32.SystemParametersInfoA(113, 0,setspeed, 2 | 1) 255 | @staticmethod 256 | def WaitKey(vk_code,time_out) -> bool: 257 | intm = time.time() 258 | while True: 259 | if((time.time() - intm)*1000>time_out):return False 260 | if vk_code != 0: 261 | if(bool(DMInput.winuser32.GetAsyncKeyState(vk_code)&0x8000)): 262 | return True 263 | else: 264 | for (k,v) in DMInput.key_table.items(): 265 | if DMInput.GetKeyState(v): 266 | return True 267 | return True 268 | @staticmethod 269 | def WheelDown() -> None: 270 | MOUSEEVENTF_WHEEL = 0x0800 271 | DMInput.winuser32.mouse_event(MOUSEEVENTF_WHEEL,0,0,-20,0) 272 | @staticmethod 273 | def WheelUp() -> None: 274 | MOUSEEVENTF_WHEEL = 0x0800 275 | DMInput.winuser32.mouse_event(MOUSEEVENTF_WHEEL,0,0,20,0) 276 | -------------------------------------------------------------------------------- /dmpic.py: -------------------------------------------------------------------------------- 1 | ''' 2 | /* 3 | * Copyright 2020 DMProject and contributors. 4 | * 5 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 6 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 7 | * 8 | * https://github.com/super1207/DMProject/blob/master/LICENSE 9 | */ 10 | ''' 11 | 12 | ''' 13 | @Description: 大漠插件7.1904[图色]API部分的python实现 14 | @FilePath: dmpic.py 15 | ''' 16 | import win32gui, win32ui, win32con 17 | from PIL import Image 18 | 19 | class DMPIC(): 20 | 21 | @staticmethod 22 | def Capture(x1, y1, x2, y2, file) -> None: 23 | hwndDC = win32gui.GetWindowDC(0) 24 | mfcDC = win32ui.CreateDCFromHandle(hwndDC) 25 | saveDC = mfcDC.CreateCompatibleDC() 26 | saveBitMap = win32ui.CreateBitmap() 27 | saveBitMap.CreateCompatibleBitmap(mfcDC, x2-x1, y2-y1) 28 | saveDC.SelectObject(saveBitMap) 29 | saveDC.BitBlt((0, 0), (x2-x1, y2-y1), mfcDC, (x1, y1), win32con.SRCCOPY) 30 | saveBitMap.SaveBitmapFile(saveDC, file) 31 | win32gui.DeleteObject(saveBitMap.GetHandle()) 32 | saveDC.DeleteDC() 33 | mfcDC.DeleteDC() 34 | win32gui.ReleaseDC(0,hwndDC) 35 | 36 | @staticmethod 37 | def CapturePng(x1, y1, x2, y2, file) -> None: 38 | hwndDC = win32gui.GetWindowDC(0) 39 | mfcDC = win32ui.CreateDCFromHandle(hwndDC) 40 | saveDC = mfcDC.CreateCompatibleDC() 41 | saveBitMap = win32ui.CreateBitmap() 42 | saveBitMap.CreateCompatibleBitmap(mfcDC, x2-x1, y2-y1) 43 | saveDC.SelectObject(saveBitMap) 44 | saveDC.BitBlt((0, 0), (x2-x1, y2-y1), mfcDC, (x1, y1), win32con.SRCCOPY) 45 | bmpinfo = saveBitMap.GetInfo() 46 | bmpstr = saveBitMap.GetBitmapBits(True) 47 | try: 48 | pil_image = Image.frombuffer('RGB',(bmpinfo['bmWidth'], bmpinfo['bmHeight']),bmpstr,'raw', 'BGRX', 0, 1) 49 | pil_image.save(file) 50 | except: 51 | raise Exception('call CapturePng failed') 52 | finally: 53 | win32gui.DeleteObject(saveBitMap.GetHandle()) 54 | saveDC.DeleteDC() 55 | mfcDC.DeleteDC() 56 | win32gui.ReleaseDC(0,hwndDC) 57 | 58 | @staticmethod 59 | def CaptureJpg(x1, y1, x2, y2, file) -> None: 60 | DMPIC.CapturePng(x1, y1, x2, y2, file) # PIL可以根据拓展名来自动选择保存类型 61 | 62 | # test 63 | # import time 64 | # t1 = time.time() 65 | # DMPIC.Capture(0,0,600,600,"aaa.bmp") 66 | # t2 = time.time() 67 | # DMPIC.CapturePng(0,0,600,600,"aaa.png") 68 | # t3 = time.time() 69 | # DMPIC.CaptureJpg(0,0,600,600,"aaa.jpg") 70 | # t4 = time.time() 71 | # print(t2-t1,t3-t2,t4-t3) 72 | -------------------------------------------------------------------------------- /dmsystem.py: -------------------------------------------------------------------------------- 1 | ''' 2 | /* 3 | * Copyright 2020 DMProject and contributors. 4 | * 5 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 6 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 7 | * 8 | * https://github.com/super1207/DMProject/blob/master/LICENSE 9 | */ 10 | ''' 11 | 12 | ''' 13 | @Description: 大漠插件7.1904[系统]API部分的python实现 14 | @FilePath: dmsystem.py 15 | ''' 16 | 17 | import ctypes 18 | import winreg 19 | import random 20 | import traceback 21 | import ctypes.wintypes 22 | import urllib.request 23 | import time 24 | import platform 25 | import uuid 26 | import subprocess 27 | 28 | 29 | 30 | class DMSystem(): 31 | winKernel32 = ctypes.windll.kernel32 32 | winuser32 = ctypes.windll.LoadLibrary('user32.dll') 33 | wingdi32 = ctypes.windll.LoadLibrary('gdi32.dll') 34 | winntdll = ctypes.windll.LoadLibrary('ntdll.dll') 35 | winwinmm = ctypes.windll.LoadLibrary('winmm.dll') 36 | @staticmethod 37 | def Beep(f,duration)->None: 38 | is_ok:bool = DMSystem.winKernel32.Beep(f,duration) 39 | if not is_ok: 40 | raise Exception('Call Beep failed') 41 | @staticmethod 42 | def CheckFontSmooth()->bool: 43 | ret = ctypes.c_bool() 44 | SPI_GETFONTSMOOTHING = 0x004A 45 | is_ok:bool = DMSystem.winuser32.SystemParametersInfoW(SPI_GETFONTSMOOTHING,0, ctypes.pointer(ret), 0) 46 | if not is_ok: 47 | raise Exception('Call CheckFontSmooth failed') 48 | return ret.value 49 | @staticmethod 50 | def CheckUAC()->bool: 51 | key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System') 52 | value, typee = winreg.QueryValueEx(key, 'EnableLUA') 53 | return value == 1 54 | @staticmethod 55 | def Delay(mis)->bool: 56 | is_ok:bool = (DMSystem.winKernel32.Sleep(mis) == 0) 57 | if not is_ok: 58 | raise Exception('Call Delay failed') 59 | @staticmethod 60 | def Delays(mis_min,mis_max)->bool: 61 | is_ok:bool = Delay(random.randint(mis_min,mis_max)) 62 | if not is_ok: 63 | raise Exception('Call Delays failed') 64 | @staticmethod 65 | def DisableCloseDisplayAndSleep() -> None: 66 | ret = ctypes.c_bool() 67 | SPI_SETSCREENSAVEACTIVE = 0x0011 68 | SPIF_SENDWININICHANGE = 0x0002 69 | is_ok:bool = DMSystem.winuser32.SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE,0, ctypes.pointer(ret), SPIF_SENDWININICHANGE) 70 | if not is_ok: 71 | raise Exception('Call DisableCloseDisplayAndSleep failed') 72 | @staticmethod 73 | def DisableFontSmooth() -> None: 74 | SPI_SETFONTSMOOTHING = 0x004B 75 | SPIF_SENDWININICHANGE = 0x0002 76 | is_ok:bool = DMSystem.winuser32.SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE,0, 0, SPIF_SENDWININICHANGE) 77 | if not is_ok: 78 | raise Exception('Call DisableFontSmooth failed') 79 | @staticmethod 80 | def DisablePowerSave() -> None: 81 | SPI_SETLOWPOWERTIMEOUT = 0x0051 82 | SPI_SETPOWEROFFTIMEOUT = 0x0052 83 | is_ok:bool = DMSystem.winuser32.SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT,0,0,0) 84 | if not is_ok: 85 | raise Exception('Call DisablePowerSave failed') 86 | is_ok:bool = DMSystem.winuser32.SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT,0,0,0) 87 | if not is_ok: 88 | raise Exception('Call DisablePowerSave failed') 89 | @staticmethod 90 | def DisableScreenSave() -> None: 91 | SPI_SETSCREENSAVEACTIVE = 0x0011 92 | is_ok:bool = DMSystem.winuser32.SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,0,0,0) 93 | if not is_ok: 94 | raise Exception('Call DisablePowerSave failed') 95 | @staticmethod 96 | def EnableFontSmooth() -> None: 97 | SPI_SETFONTSMOOTHING = 0x004B 98 | SPIF_SENDWININICHANGE = 0x0002 99 | is_ok:bool = DMSystem.winuser32.SystemParametersInfoW(SPI_SETFONTSMOOTHING,1,0, SPIF_SENDWININICHANGE) 100 | if not is_ok: 101 | raise Exception('Call EnableFontSmooth failed') 102 | @staticmethod 103 | def ExitOs(type_) -> None: 104 | EWX_LOGOFF = 0x0000 105 | EWX_POWEROFF = 0x0008 106 | EWX_REBOOT = 0x0002 107 | EWX_FORCE = 0x0004 108 | is_ok:bool = False 109 | if type_ == 0: 110 | is_ok = DMSystem.winuser32.ExitWindowsEx(EWX_FORCE | EWX_LOGOFF) 111 | elif type_ == 1: 112 | is_ok = DMSystem.winuser32.ExitWindowsEx(EWX_FORCE | EWX_POWEROFF) 113 | elif type == 2: 114 | is_ok = DMSystem.winuser32.ExitWindowsEx(EWX_FORCE | EWX_REBOOT) 115 | else: 116 | raise Exception('Call ExitOs failed') 117 | if not is_ok: 118 | raise Exception('Call ExitOs failed') 119 | @staticmethod 120 | def GetClipboard() -> str: 121 | CF_UNICODETEXT = 13 122 | is_ok:bool = DMSystem.winuser32.OpenClipboard(0) 123 | if not is_ok: 124 | raise Exception('Call GetClipboard failed') 125 | hd=DMSystem.winuser32.GetClipboardData(CF_UNICODETEXT) 126 | if not hd: 127 | DMSystem.winuser32.CloseClipboard() 128 | raise Exception('Call GetClipboard failed:Is not UNICODETEXT') 129 | ss=ctypes.c_wchar_p(hd) 130 | DMSystem.winuser32.CloseClipboard() 131 | return ss.value 132 | @staticmethod 133 | def GetCpuType() -> int: 134 | class _SYSTEM_INFO(ctypes.Structure): 135 | _fields_ = [ 136 | ("dwOemId",ctypes.wintypes.DWORD), 137 | ("dwProcessorType",ctypes.wintypes.DWORD), 138 | ("lpMinimumApplicationAddress",ctypes.wintypes.LPVOID), 139 | ("lpMaximumApplicationAddress",ctypes.wintypes.LPVOID), 140 | ("dwActiveProcessorMask",ctypes.wintypes.LPVOID), 141 | ("dwNumberOfProcessors",ctypes.wintypes.DWORD), 142 | ("dwProcessorType",ctypes.wintypes.DWORD), 143 | ("dwAllocationGranularity",ctypes.wintypes.DWORD), 144 | ("wProcessorLevel",ctypes.wintypes.WORD), 145 | ("wProcessorRevision",ctypes.wintypes.WORD), 146 | ] 147 | lpSystemInfo = _SYSTEM_INFO() 148 | DMSystem.winKernel32.GetNativeSystemInfo(ctypes.byref(lpSystemInfo)) 149 | if(lpSystemInfo.dwProcessorType in [386,486,586,2200]): 150 | return 1 151 | elif lpSystemInfo.dwProcessorType == 8664: 152 | return 2 153 | else: return 0 154 | @staticmethod 155 | def GetDir(type_) -> str: 156 | if type_ == 0: 157 | pathstr = ctypes.create_string_buffer(''.encode(), 1000) 158 | loadlen = DMSystem.winKernel32.GetCurrentDirectoryA(1000,pathstr) 159 | if loadlen <= 0: 160 | raise Exception('Call GetDir failed') 161 | return ctypes.string_at(pathstr).decode('GB2312') 162 | elif type_ == 1: 163 | pathstr = ctypes.create_string_buffer(''.encode(), 1000) 164 | loadlen = DMSystem.winKernel32.GetSystemDirectoryA(pathstr,1000) 165 | if loadlen <= 0: 166 | raise Exception('Call GetDir failed') 167 | return ctypes.string_at(pathstr).decode('GB2312') 168 | elif type_ == 2: 169 | pathstr = ctypes.create_string_buffer(''.encode(), 1000) 170 | loadlen = DMSystem.winKernel32.GetWindowsDirectoryA(pathstr,1000) 171 | if loadlen <= 0: 172 | raise Exception('Call GetDir failed') 173 | return ctypes.string_at(pathstr).decode('GB2312') 174 | elif type_ == 3: 175 | pathstr = ctypes.create_string_buffer(''.encode(), 1000) 176 | loadlen = DMSystem.winKernel32.GetTempPathA(1000,pathstr) 177 | if loadlen <= 0: 178 | raise Exception('Call GetDir failed') 179 | return ctypes.string_at(pathstr).decode('GB2312') 180 | elif type_ == 4: 181 | pathstr = ctypes.create_string_buffer(''.encode(), 1000) 182 | loadlen = DMSystem.winKernel32.GetModuleFileNameA(0,pathstr,1000) 183 | if loadlen <= 0: 184 | raise Exception('Call GetDir failed') 185 | return ctypes.string_at(pathstr).decode('GB2312') 186 | else:raise Exception('Call GetDir failed') 187 | @staticmethod 188 | def GetDiskSerial() -> str: 189 | '''需安装wmi,且winxp无效''' 190 | import wmi 191 | disk = [physical_disk.SerialNumber.strip() for physical_disk in wmi.WMI().Win32_DiskDrive()] 192 | if len(disk) == 0: 193 | raise Exception('Call GetDiskSerial failed') 194 | else: 195 | return disk[len(disk) - 1] 196 | @staticmethod 197 | def GetDPI() -> bool: 198 | ret:bool = True 199 | DESKTOPHORZRE = 118 200 | HORZRES = 8 201 | DESKTOPVERTRES = 117 202 | VERTRES = 10 203 | hdc = DMSystem.winuser32.GetDC(0) 204 | t = DMSystem.wingdi32.GetDeviceCaps(hdc, DESKTOPHORZRE) 205 | d = DMSystem.wingdi32.GetDeviceCaps(hdc, HORZRES) 206 | if t != d:ret = False 207 | t = DMSystem.wingdi32.GetDeviceCaps(hdc, DESKTOPVERTRES) 208 | d = DMSystem.wingdi32.GetDeviceCaps(hdc, VERTRES) 209 | if t != d:ret = False 210 | DMSystem.winuser32.ReleaseDC(0, hdc) 211 | return ret 212 | @staticmethod 213 | def GetMachineCode() -> str: 214 | '''需安装wmi,且winxp无效''' 215 | import wmi 216 | board = [physical_board for physical_board in wmi.WMI().Win32_BaseBoard()] 217 | if len(board) == 0: 218 | raise Exception('Call GetMachineCode failed') 219 | else: 220 | return board[len(board) - 1].qualifiers['UUID'][1:-1].strip() 221 | @staticmethod 222 | def GetNetTime() -> str: 223 | resp = urllib.request.urlopen('http://www.baidu.com') 224 | ts = resp.info()['Date'] 225 | ltime= time.strptime(ts[5:25], "%d %b %Y %H:%M:%S") 226 | ttime=time.localtime(time.mktime(ltime)+8*60*60) 227 | rettime = "%u-%02u-%02u %02u:%02u:%02u"%(ttime.tm_year,ttime.tm_mon,ttime.tm_mday,ttime.tm_hour,ttime.tm_min,ttime.tm_sec) 228 | return rettime 229 | @staticmethod 230 | def GetNetTimeByIp(ip) -> str: 231 | resp = urllib.request.urlopen("http://"+ip) 232 | ts = resp.info()['Date'] 233 | ltime= time.strptime(ts[5:25], "%d %b %Y %H:%M:%S") 234 | ttime=time.localtime(time.mktime(ltime)+8*60*60) 235 | rettime = "%u-%02u-%02u %02u:%02u:%02u"%(ttime.tm_year,ttime.tm_mon,ttime.tm_mday,ttime.tm_hour,ttime.tm_min,ttime.tm_sec) 236 | return rettime 237 | @staticmethod 238 | def GetNetTimeSafe(ip) -> str: 239 | return DMSystem.GetNetTimeByIp(ip) 240 | @staticmethod 241 | def GetOsBuildNumber() -> int: 242 | dwBuildNumber = ctypes.wintypes.DWORD() 243 | DMSystem.winntdll.RtlGetNtVersionNumbers(0,0,ctypes.byref(dwBuildNumber)) 244 | return dwBuildNumber.value & 0xffff 245 | @staticmethod 246 | def GetOsType() -> int: 247 | dwMajorVer = ctypes.wintypes.DWORD() 248 | dwMinorVer = ctypes.wintypes.DWORD() 249 | DMSystem.winntdll.RtlGetNtVersionNumbers(ctypes.byref(dwMajorVer),ctypes.byref(dwMinorVer),0) 250 | dwMajorVer = dwMajorVer.value 251 | dwMinorVer = dwMinorVer.value 252 | if dwMajorVer == 4: 253 | return 0 254 | elif dwMajorVer == 5: 255 | if dwMinorVer in [0,1]: 256 | return 1 257 | else: 258 | return 2 259 | elif dwMajorVer == 6 and dwMinorVer == 1: 260 | return 3 261 | elif dwMajorVer == 6 and dwMinorVer == 0: 262 | return 4 263 | elif dwMajorVer == 6 and dwMinorVer == 2: 264 | return 5 265 | elif dwMajorVer == 6 and dwMinorVer == 3: 266 | return 6 267 | elif dwMajorVer == 10: 268 | return 7 269 | raise Exception('Call GetOsType failed') 270 | @staticmethod 271 | def GetScreenDepth() -> int: 272 | BITSPIXEL = 12 273 | hdc = DMSystem.winuser32.GetDC(0) 274 | dmBitDepth = DMSystem.wingdi32.GetDeviceCaps(hdc,BITSPIXEL) 275 | DMSystem.winuser32.ReleaseDC(0, hdc) 276 | return dmBitDepth 277 | @staticmethod 278 | def GetScreenHeight() -> int: 279 | VERTRES = 10 280 | hdc = DMSystem.winuser32.GetDC(0) 281 | height = DMSystem.wingdi32.GetDeviceCaps(hdc,VERTRES) 282 | DMSystem.winuser32.ReleaseDC(0, hdc) 283 | return height 284 | @staticmethod 285 | def GetScreenWidth() -> int: 286 | HORZRES = 8 287 | hdc = DMSystem.winuser32.GetDC(0) 288 | weight = DMSystem.wingdi32.GetDeviceCaps(hdc,HORZRES) 289 | DMSystem.winuser32.ReleaseDC(0, hdc) 290 | return weight 291 | @staticmethod 292 | def GetTime() -> int: 293 | return DMSystem.winKernel32.timeGetTime() 294 | @staticmethod 295 | def Is64Bit() -> bool: 296 | class _SYSTEM_INFO(ctypes.Structure): 297 | _fields_ = [ 298 | ("dwOemId",ctypes.wintypes.DWORD), 299 | ("dwProcessorType",ctypes.wintypes.DWORD), 300 | ("lpMinimumApplicationAddress",ctypes.wintypes.LPVOID), 301 | ("lpMaximumApplicationAddress",ctypes.wintypes.LPVOID), 302 | ("dwActiveProcessorMask",ctypes.wintypes.LPVOID), 303 | ("dwNumberOfProcessors",ctypes.wintypes.DWORD), 304 | ("dwProcessorType",ctypes.wintypes.DWORD), 305 | ("dwAllocationGranularity",ctypes.wintypes.DWORD), 306 | ("wProcessorLevel",ctypes.wintypes.WORD), 307 | ("wProcessorRevision",ctypes.wintypes.WORD), 308 | ] 309 | lpSystemInfo = _SYSTEM_INFO() 310 | DMSystem.winKernel32.GetNativeSystemInfo(ctypes.byref(lpSystemInfo)) 311 | PROCESSOR_ARCHITECTURE_IA64 = 6 312 | PROCESSOR_ARCHITECTURE_AMD64 = 9 313 | if lpSystemInfo.dwOemId in [PROCESSOR_ARCHITECTURE_IA64,PROCESSOR_ARCHITECTURE_AMD64]: 314 | return True 315 | else: 316 | return False 317 | @staticmethod 318 | def Play(media_file)->str: 319 | mp3id = str(uuid.uuid1()) 320 | cmd = "open \""+ media_file + "\" alias " + mp3id 321 | status = DMSystem.winwinmm.mciSendStringW(cmd,0,0,0) 322 | if status != 0: 323 | raise Exception('Call Play failed') 324 | status = DMSystem.winwinmm.mciSendStringW("play "+ mp3id,0,0,0) 325 | if status != 0: 326 | DMSystem.winwinmm.mciSendStringW("close "+ mp3id,0,0,0) 327 | raise Exception('Call Play failed') 328 | return mp3id 329 | @staticmethod 330 | def RunApp(app_path,mode)->None: 331 | subprocess.Popen(app_path,shell=mode) 332 | @staticmethod 333 | def SetClipboard(value)->None: 334 | '''需安装pywin32''' 335 | import win32clipboard 336 | import win32con 337 | win32clipboard.OpenClipboard() 338 | win32clipboard.SetClipboardData(win32con.CF_UNICODETEXT, value) 339 | win32clipboard.CloseClipboard() 340 | @staticmethod 341 | def SetScreen(width,height,depth) -> None: 342 | '''需安装pywin32''' 343 | import win32api 344 | dm = win32api.EnumDisplaySettings(None, 0) 345 | dm.PelsHeight = height 346 | dm.PelsWidth = width 347 | dm.BitsPerPel = depth 348 | dm.DisplayFixedOutput = 0 349 | win32api.ChangeDisplaySettings(dm, 0) 350 | @staticmethod 351 | def SetUAC() -> None: 352 | key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System') 353 | return winreg.SetValueEx(key,'EnableLUA',0,winreg.REG_DWORD,0) 354 | @staticmethod 355 | def Stop(id_) -> None: 356 | status = DMSystem.winwinmm.mciSendStringW("stop "+ id_,0,0,0) 357 | if status != 0: 358 | raise Exception('Call Stop failed') 359 | status = DMSystem.winwinmm.mciSendStringW("close "+ id_,0,0,0) 360 | if status != 0: 361 | raise Exception('Call Stop failed') 362 | @staticmethod 363 | def ShowTaskBarIcon(hwnd,is_show) -> None: 364 | is_ok = False 365 | if is_show == 0: 366 | is_ok = DMSystem.winuser32.SetWindowLongA(67076,-20,0x80) 367 | else: 368 | is_ok = DMSystem.winuser32.SetWindowLongA(67076,-20,0x40000) 369 | if not is_ok: 370 | raise Exception('call ShowTaskBarIcon failed') 371 | -------------------------------------------------------------------------------- /dmwindow.py: -------------------------------------------------------------------------------- 1 | ''' 2 | /* 3 | * Copyright 2020 DMProject and contributors. 4 | * 5 | * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. 6 | * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. 7 | * 8 | * https://github.com/super1207/DMProject/blob/master/LICENSE 9 | */ 10 | ''' 11 | 12 | ''' 13 | @Description: 大漠插件7.1904[窗口]API部分的python实现 14 | @FilePath: dmwindow.py 15 | ''' 16 | 17 | import ctypes.wintypes 18 | import ctypes 19 | 20 | class DMWindow(): 21 | winKernel32 = ctypes.windll.kernel32 22 | winuser32 = ctypes.windll.LoadLibrary('user32.dll') 23 | wingdi32 = ctypes.windll.LoadLibrary('gdi32.dll') 24 | winntdll = ctypes.windll.LoadLibrary('ntdll.dll') 25 | winwinmm = ctypes.windll.LoadLibrary('winmm.dll') 26 | # @staticmethod 27 | # def _GetProcessNameById(process_id): 28 | # TH32CS_SNAPPROCESS = 0x00000002 29 | # hSnapshot = DMWindow.winKernel32.CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,process_id) 30 | # if not hSnapshot: 31 | # raise Exception("call _GetProcessNameById failed") 32 | # class PROCESSENTRY32(ctypes.Structure): 33 | # _fields_ = [("dwSize", ctypes.c_ulong), 34 | # ("cntUsage", ctypes.c_ulong), 35 | # ("th32ProcessID", ctypes.c_ulong), 36 | # ("th32DefaultHeapID", ctypes.c_ulong), 37 | # ("th32ModuleID", ctypes.c_ulong), 38 | # ("cntThreads", ctypes.c_ulong), 39 | # ("th32ParentProcessID", ctypes.c_ulong), 40 | # ("pcPriClassBase", ctypes.c_ulong), 41 | # ("dwFlags", ctypes.c_ulong), 42 | # ("szExeFile", ctypes.c_char * 260)] 43 | # pe32 = PROCESSENTRY32() 44 | # pe32.dwSize = ctypes.sizeof(PROCESSENTRY32) 45 | # ret = DMWindow.winKernel32.Process32First(hSnapshot,ctypes.byref(pe32)) 46 | # while ret: 47 | # if process_id == pe32.th32ProcessID: 48 | # DMWindow.winKernel32.CloseHandle(hSnapshot) 49 | # return pe32.szExeFile 50 | # ret = DMWindow.winKernel32.Process32Next(hSnapshot,ctypes.byref(pe32)) 51 | # DMWindow.winKernel32.CloseHandle(hSnapshot) 52 | # raise Exception("call _GetProcessNameById failed") 53 | 54 | @staticmethod 55 | def FindWindow(class_,title)->int: 56 | return DMWindow.FindWindowEx(None,class_,title) 57 | @staticmethod 58 | def FindWindowEx(parent,class_,title)->int: 59 | retArr = [] 60 | def mycallback(hwnd,extra) -> bool: 61 | if not DMWindow.winuser32.IsWindowVisible(hwnd): 62 | return True 63 | if class_.upper() not in DMWindow.GetWindowClass(hwnd).upper(): 64 | return True 65 | if title.upper() not in DMWindow.GetWindowTitle(hwnd).upper(): 66 | return True 67 | retArr.append(hwnd) 68 | return False 69 | CMPFUNC = ctypes.WINFUNCTYPE(ctypes.wintypes.BOOL,ctypes.wintypes.HWND, ctypes.wintypes.LPARAM) 70 | DMWindow.winuser32.EnumChildWindows(parent,CMPFUNC(mycallback),0) 71 | if len(retArr) == 0: 72 | raise Exception('call FindWindow failed:Not Found Window') 73 | return retArr[0] 74 | @staticmethod 75 | def FindWindowByProcessId(process_id,class_,title)->int: 76 | retArr = [] 77 | def mycallback(hwnd,extra) -> bool: 78 | if not DMWindow.winuser32.IsWindowVisible(hwnd): 79 | return True 80 | lProcessId = ctypes.wintypes.LONG() 81 | DMWindow.winuser32.GetWindowThreadProcessId(hwnd,ctypes.byref(lProcessId)) 82 | if process_id != lProcessId.value: 83 | return True 84 | if class_.upper() not in DMWindow.GetWindowClass(hwnd).upper(): 85 | return True 86 | if title.upper() not in DMWindow.GetWindowTitle(hwnd).upper(): 87 | return True 88 | retArr.append(hwnd) 89 | return False 90 | CMPFUNC = ctypes.WINFUNCTYPE(ctypes.wintypes.BOOL,ctypes.wintypes.HWND, ctypes.wintypes.LPARAM) 91 | DMWindow.winuser32.EnumChildWindows(None,CMPFUNC(mycallback),0) 92 | if len(retArr) == 0: 93 | raise Exception('call FindWindowByProcessId failed:Not Found Window') 94 | return retArr[0] 95 | @staticmethod 96 | def FindWindowByProcess(process_name,class_,title)->int: 97 | '''需安装psutil''' 98 | try: 99 | import psutil 100 | except: 101 | raise Exception("called FindWindowByProcess failed:psutil not install") 102 | retArr = [] 103 | def mycallback(hwnd,extra) -> bool: 104 | if not DMWindow.winuser32.IsWindowVisible(hwnd): 105 | return True 106 | lProcessId = DMWindow.GetWindowProcessId(hwnd) 107 | lProcessName = None 108 | try:#有些进程是无法打开的 109 | lProcessName = psutil.Process(lProcessId).name() 110 | except: 111 | return True 112 | if(lProcessName == None):lProcessName = "" 113 | if process_name.upper() not in lProcessName.upper(): 114 | return True 115 | if class_.upper() not in DMWindow.GetWindowClass(hwnd).upper(): 116 | return True 117 | if title.upper() not in DMWindow.GetWindowTitle(hwnd).upper(): 118 | return True 119 | retArr.append(hwnd) 120 | return False 121 | CMPFUNC = ctypes.WINFUNCTYPE(ctypes.wintypes.BOOL,ctypes.wintypes.HWND, ctypes.wintypes.LPARAM) 122 | DMWindow.winuser32.EnumChildWindows(None,CMPFUNC(mycallback),0) 123 | if len(retArr) == 0: 124 | raise Exception('call FindWindowByProcessId failed:Not Found Window') 125 | return retArr[0] 126 | @staticmethod 127 | def GetProcessInfo(pid): 128 | '''需安装psutil''' 129 | try: 130 | import psutil 131 | except: 132 | raise Exception("called GetProcessInfo failed:psutil not install") 133 | p = psutil.Process(pid) 134 | return p.name()+'|'+p.exe()+'|'+str(p.cpu_percent())+'|'+str(p.memory_info().rss) 135 | @staticmethod 136 | def GetWindowClass(hwnd) -> str: 137 | classStr = ctypes.create_string_buffer(''.encode(), 1000) 138 | is_ok:bool = DMWindow.winuser32.GetClassNameA(hwnd,classStr,1000) 139 | if (not is_ok) and DMWindow.winKernel32.GetLastError() != 0: 140 | raise Exception("call GetWindowClass failed") 141 | return ctypes.string_at(classStr).decode('GB2312') 142 | @staticmethod 143 | def GetWindowProcessId(hwnd) -> int: 144 | lProcessId = ctypes.wintypes.LONG() 145 | is_ok:bool = DMWindow.winuser32.GetWindowThreadProcessId(hwnd,ctypes.byref(lProcessId)) 146 | if (not is_ok) and DMWindow.winKernel32.GetLastError() != 0: 147 | raise Exception("call GetWindowProcessId failed") 148 | return lProcessId.value 149 | @staticmethod 150 | def GetWindowTitle(hwnd) -> str: 151 | titleStr = ctypes.create_string_buffer(''.encode(), 1000) 152 | is_ok:bool = DMWindow.winuser32.GetWindowTextA(hwnd,titleStr,1000) 153 | if (not is_ok) and DMWindow.winKernel32.GetLastError() != 0: 154 | raise Exception("call GetWindowTitle failed") 155 | return ctypes.string_at(titleStr).decode('GB2312') 156 | @staticmethod 157 | def GetWindowProcessPath(hwnd) -> str: 158 | '''需安装psutil''' 159 | try: 160 | import psutil 161 | except: 162 | raise Exception("called GetWindowProcessPath failed:psutil not install") 163 | process_id = DMWindow.GetWindowProcessId(hwnd) 164 | p = psutil.Process(process_id) 165 | return p.exe() 166 | @staticmethod 167 | def GetSpecialWindow(flag) -> int: 168 | if flag == 0: 169 | return DMWindow.winuser32.GetDesktopWindow() 170 | elif flag == 1: 171 | return DMWindow.winuser32.FindWindowW("Shell_TrayWnd",0) 172 | else: 173 | raise Exception('call GetSpecialWindow Failed') 174 | @staticmethod 175 | def GetForegroundWindow() -> int: 176 | is_ok:int = DMWindow.winuser32.GetForegroundWindow() 177 | if not is_ok: 178 | raise Exception('call GetForegroundWindow Failed') 179 | return is_ok 180 | @staticmethod 181 | def GetForegroundFocus() -> int: 182 | wnd:int = DMWindow.GetForegroundWindow() 183 | if not wnd: 184 | raise Exception('call GetForegroundFocus Failed') 185 | SelfThreadId = DMWindow.winKernel32.GetCurrentThreadId() 186 | ForeThreadId = DMWindow.winuser32.GetWindowThreadProcessId(wnd,0) 187 | DMWindow.winuser32.AttachThreadInput(ForeThreadId, SelfThreadId, True) 188 | wnd = DMWindow.winuser32.GetFocus() 189 | DMWindow.winuser32.AttachThreadInput(ForeThreadId, SelfThreadId, False) 190 | if not wnd: 191 | raise Exception('call GetForegroundFocus Failed') 192 | return wnd 193 | @staticmethod 194 | def GetMousePointWindow() ->int: 195 | class POINT(ctypes.Structure): 196 | _fields_ = [ 197 | ("x",ctypes.wintypes.LONG), 198 | ("y",ctypes.wintypes.LONG) 199 | ] 200 | point = POINT() 201 | DMWindow.winuser32.GetCursorPos(ctypes.byref(point)) 202 | hwnd = DMWindow.winuser32.WindowFromPoint(point) 203 | if not hwnd: 204 | raise Exception('call GetMousePointWindow failed') 205 | return hwnd 206 | @staticmethod 207 | def GetPointWindow(x,y) -> int: 208 | class POINT(ctypes.Structure): 209 | _fields_ = [ 210 | ("x",ctypes.wintypes.LONG), 211 | ("y",ctypes.wintypes.LONG) 212 | ] 213 | point = POINT() 214 | point.x = x 215 | point.y = y 216 | hwnd = DMWindow.winuser32.WindowFromPoint(point) 217 | if not hwnd: 218 | raise Exception('call GetMousePointWindow failed') 219 | return hwnd 220 | @staticmethod 221 | def GetWindow(hwnd,flag) -> int: 222 | rethwnd = None 223 | if flag == 0: 224 | rethwnd = DMWindow.winuser32.GetParent(hwnd) 225 | elif flag == 1: 226 | rethwnd = DMWindow.winuser32.GetWindow(hwnd,5) 227 | # def mycallback(hwnd,extra) -> bool: 228 | # nonlocal rethwnd 229 | # rethwnd = hwnd 230 | # return False 231 | # CMPFUNC = ctypes.WINFUNCTYPE(ctypes.wintypes.BOOL,ctypes.wintypes.HWND, ctypes.wintypes.LPARAM) 232 | # DMWindow.winuser32.EnumChildWindows(hwnd,CMPFUNC(mycallback),0) 233 | elif flag == 2: 234 | rethwnd = DMWindow.winuser32.GetWindow(hwnd,0) 235 | elif flag == 3: 236 | rethwnd = DMWindow.winuser32.GetWindow(hwnd,1) 237 | elif flag == 4: 238 | rethwnd = DMWindow.winuser32.GetWindow(hwnd,2) 239 | elif flag == 5: 240 | rethwnd = DMWindow.winuser32.GetWindow(hwnd,3) 241 | elif flag == 6: 242 | rethwnd = DMWindow.winuser32.GetWindow(hwnd,4) 243 | if not rethwnd: 244 | rethwnd = DMWindow.winuser32.GetParent(hwnd) 245 | if not rethwnd: 246 | rethwnd = hwnd 247 | elif flag == 7: 248 | rethwnd = DMWindow.winuser32.GetTopWindow(hwnd) 249 | # top = hwnd 250 | # while True: 251 | # hd = DMWindow.winuser32.GetParent(top) 252 | # if not hd: 253 | # rethwnd = top 254 | # break 255 | # top = hd 256 | if not rethwnd: 257 | raise Exception('call GetWindow failed') 258 | return rethwnd 259 | @staticmethod 260 | def GetWindowRect(hwnd) -> tuple: 261 | rect = ctypes.wintypes.RECT() 262 | is_ok:bool = DMWindow.winuser32.GetWindowRect(hwnd,ctypes.byref(rect)) 263 | if not is_ok: 264 | raise Exception('call GetWindowRect failed') 265 | return (rect.left,rect.top,rect.right,rect.bottom) 266 | @staticmethod 267 | def GetWindowState(hwnd,flag) -> bool: 268 | if flag == 0: 269 | return DMWindow.winuser32.IsWindow(hwnd) == 1 270 | elif flag == 1: 271 | return DMWindow.GetForegroundWindow() == hwnd 272 | elif flag == 2: 273 | return DMWindow.winuser32.IsWindowVisible(hwnd) == 1 274 | elif flag == 3: 275 | return DMWindow.winuser32.IsIconic(hwnd) == 1 276 | elif flag == 4: 277 | return DMWindow.winuser32.IsZoomed(hwnd) == 1 278 | elif flag == 5: 279 | GWL_EXSTYLE = -20 280 | WS_EX_TOPMOST = 0x00000008 281 | if (DMWindow.winuser32.GetWindowLongA(hwnd,GWL_EXSTYLE) & WS_EX_TOPMOST): 282 | return True 283 | else: 284 | return False 285 | elif flag == 6 or flag == 8: 286 | return DMWindow.winuser32.IsHungAppWindow(hwnd) == 1 287 | elif flag == 7: 288 | return DMWindow.winuser32.IsWindowEnabled(hwnd) == 1 289 | elif flag == 9: 290 | def Is64Bit() -> bool: 291 | class _SYSTEM_INFO(ctypes.Structure): 292 | _fields_ = [ 293 | ("dwOemId",ctypes.wintypes.DWORD), 294 | ("dwProcessorType",ctypes.wintypes.DWORD), 295 | ("lpMinimumApplicationAddress",ctypes.wintypes.LPVOID), 296 | ("lpMaximumApplicationAddress",ctypes.wintypes.LPVOID), 297 | ("dwActiveProcessorMask",ctypes.wintypes.LPVOID), 298 | ("dwNumberOfProcessors",ctypes.wintypes.DWORD), 299 | ("dwProcessorType",ctypes.wintypes.DWORD), 300 | ("dwAllocationGranularity",ctypes.wintypes.DWORD), 301 | ("wProcessorLevel",ctypes.wintypes.WORD), 302 | ("wProcessorRevision",ctypes.wintypes.WORD), 303 | ] 304 | lpSystemInfo = _SYSTEM_INFO() 305 | DMWindow.winKernel32.GetNativeSystemInfo(ctypes.byref(lpSystemInfo)) 306 | PROCESSOR_ARCHITECTURE_IA64 = 6 307 | PROCESSOR_ARCHITECTURE_AMD64 = 9 308 | if lpSystemInfo.dwOemId in [PROCESSOR_ARCHITECTURE_IA64,PROCESSOR_ARCHITECTURE_AMD64]: 309 | return True 310 | else: 311 | return False 312 | if not Is64Bit(): 313 | return False 314 | isWow64Process = ctypes.wintypes.BOOL(True) 315 | processId = DMWindow.GetWindowProcessId(hwnd) 316 | PROCESS_QUERY_INFORMATION = 0x0400 317 | hProcess = DMWindow.winKernel32.OpenProcess(PROCESS_QUERY_INFORMATION, False, processId) 318 | if not hProcess: 319 | raise Exception('call GetWindowState failed:OpenProcess') 320 | is_ok:bool = DMWindow.winKernel32.IsWow64Process(hProcess,ctypes.pointer(isWow64Process)) 321 | DMWindow.winKernel32.CloseHandle(hProcess) 322 | if not is_ok: 323 | raise Exception('call GetWindowState failed:IsWow64Process') 324 | if isWow64Process.value: 325 | return False 326 | return True 327 | @staticmethod 328 | def GetClientSize(hwnd) -> tuple: 329 | rect = ctypes.wintypes.RECT() 330 | is_ok:bool = DMWindow.winuser32.GetClientRect(hwnd,ctypes.byref(rect)) 331 | if not is_ok: 332 | raise Exception('call GetClientRect failed') 333 | return (rect.right,rect.bottom) 334 | @staticmethod 335 | def ClientToScreen(hwnd,x,y) -> tuple: 336 | point = ctypes.wintypes.POINT() 337 | point.x = x 338 | point.y = y 339 | is_ok:bool = DMWindow.winuser32.ClientToScreen(hwnd,ctypes.byref(point)) 340 | if not is_ok: 341 | raise Exception('call ClientToScreen failed') 342 | return (point.x,point.y) 343 | @staticmethod 344 | def ScreenToClient(hwnd,x,y) -> tuple: 345 | point = ctypes.wintypes.POINT() 346 | point.x = x 347 | point.y = y 348 | is_ok:bool = DMWindow.winuser32.ScreenToClient(hwnd,ctypes.byref(point)) 349 | if not is_ok: 350 | raise Exception('call ScreenToClient failed') 351 | return (point.x,point.y) 352 | @staticmethod 353 | def GetClientRect(hwnd) -> tuple: 354 | x1,y1 = DMWindow.ClientToScreen(hwnd,0,0) 355 | x2,y2 = DMWindow.GetClientSize(hwnd) 356 | x2,y2 = DMWindow.ClientToScreen(hwnd,x2,y2) 357 | return (x1,y1,x2,y2) 358 | @staticmethod 359 | def MoveWindow(hwnd,x,y) -> None: 360 | x1,y1,x2,y2 = DMWindow.GetWindowRect(hwnd) 361 | is_ok:bool = DMWindow.winuser32.MoveWindow(hwnd,0,0,x2-x1,y2-y1,True) 362 | if not is_ok: 363 | raise Exception('call MoveWindow failed') 364 | @staticmethod 365 | def SetWindowSize(hwnd,width,height) -> None: 366 | x1,y1,x2,y2 = DMWindow.GetWindowRect(hwnd) 367 | is_ok:bool = DMWindow.winuser32.MoveWindow(hwnd,x1,y1,width,height,True) 368 | if not is_ok: 369 | raise Exception('call SetWindowSize failed') 370 | @staticmethod 371 | def SetWindowText(hwnd,title): 372 | is_ok:bool = DMWindow.winuser32.SetWindowTextW(hwnd,title) 373 | if not is_ok: 374 | raise Exception('call SetWindowText failed') 375 | @staticmethod 376 | def SetWindowTransparent(hwnd,trans): 377 | is_ok:bool = DMWindow.winuser32.SetLayeredWindowAttributes(hwnd, 0, trans, 2) 378 | if not is_ok: 379 | raise Exception('call SetWindowTransparent failed') 380 | @staticmethod 381 | def SetClientSize(hwnd,width,height) -> None: 382 | wx1,wy1,wx2,wy2 = DMWindow.GetWindowRect(hwnd) 383 | w,h = DMWindow.GetClientSize(hwnd) 384 | DMWindow.SetWindowSize(hwnd,wx2-wx1+width-w,wy2-wy1+height-h) 385 | @staticmethod 386 | def EnumProcess(name) -> str: 387 | '''需安装psutil''' 388 | try: 389 | import psutil 390 | except: 391 | raise Exception("called EnumProcess failed:psutil not install") 392 | ret = [] 393 | for proc in psutil.process_iter(): 394 | pinfo = proc.as_dict(attrs=['pid','name','create_time']) 395 | pname = '' 396 | if pinfo['name'] != None: 397 | pname = pinfo['name'].upper() 398 | if name.upper() in pname: 399 | ret.append((pinfo['pid'],pinfo['create_time'])) 400 | if len(ret) == 0: 401 | raise Exception("called EnumProcess failed:process not found") 402 | ret = sorted(ret,key = lambda x:x[1]) 403 | ret = [str(i[0]) for i in ret] 404 | return ','.join(ret) 405 | @staticmethod 406 | def SendPaste(hwnd) -> None: 407 | class WINDOWPLACEMENT(ctypes.Structure): 408 | _fields_ = [ 409 | ("length",ctypes.wintypes.UINT), 410 | ("flags",ctypes.wintypes.UINT), 411 | ("showCmd",ctypes.wintypes.UINT), 412 | ("ptMinPosition",ctypes.wintypes.POINT), 413 | ("ptMaxPosition",ctypes.wintypes.POINT), 414 | ("rcNormalPosition",ctypes.wintypes.RECT) 415 | ] 416 | if not DMWindow.GetWindowState(hwnd,0): 417 | raise Exception('call SendPaste failed:window not exist') 418 | wtp = WINDOWPLACEMENT() 419 | DMWindow.winuser32.GetWindowPlacement(hwnd,ctypes.byref(wtp)) 420 | if(wtp.showCmd != 1): # 没有最小化 421 | if wtp.showCmd == 2:#被最小化了 422 | wtp.showCmd = 9 423 | DMWindow.winuser32.SetWindowPlacement(hwnd,ctypes.byref(wtp)) 424 | # 正常情况下wtp.showCmd为3,表示前台 425 | DMWindow.winuser32.SetForegroundWindow(hwnd) 426 | DMWindow.winuser32.BringWindowToTop(hwnd) 427 | DMWindow.winuser32.keybd_event(0x11, 0, 0x0001, 0); 428 | DMWindow.winuser32.keybd_event(86, 0, 0x0001, 0); 429 | DMWindow.winuser32.keybd_event(86, 0, 0x0001|0x0002, 0) 430 | DMWindow.winuser32.keybd_event(0x11, 0, 0x0001|0x0002, 0) 431 | @staticmethod 432 | def SetWindowState(hwnd,flag): 433 | class WINDOWPLACEMENT(ctypes.Structure): 434 | _fields_ = [ 435 | ("length",ctypes.wintypes.UINT), 436 | ("flags",ctypes.wintypes.UINT), 437 | ("showCmd",ctypes.wintypes.UINT), 438 | ("ptMinPosition",ctypes.wintypes.POINT), 439 | ("ptMaxPosition",ctypes.wintypes.POINT), 440 | ("rcNormalPosition",ctypes.wintypes.RECT) 441 | ] 442 | is_ok = False 443 | if flag == 0: 444 | is_ok = DMWindow.winuser32.SendMessageW(hwnd, 0x0010, 0, 0) 445 | elif flag == 1: 446 | is_ok = DMWindow.winuser32.SetActiveWindow(hwnd) 447 | elif flag == 2 or flag == 3: 448 | is_ok = DMWindow.winuser32.ShowWindow(hwnd,2) 449 | elif flag == 4: 450 | is_ok = DMWindow.winuser32.ShowWindow(hwnd,3) 451 | is_ok = DMWindow.winuser32.SetActiveWindow(hwnd) 452 | elif flag == 5: 453 | wtp = WINDOWPLACEMENT() 454 | is_ok = DMWindow.winuser32.GetWindowPlacement(hwnd,ctypes.byref(wtp)) 455 | wtp.showCmd = 9 456 | is_ok = DMWindow.winuser32.SetWindowPlacement(hwnd,ctypes.byref(wtp)) 457 | elif flag == 6: 458 | wtp = WINDOWPLACEMENT() 459 | is_ok = DMWindow.winuser32.GetWindowPlacement(hwnd,ctypes.byref(wtp)) 460 | wtp.showCmd = 0 461 | is_ok = DMWindow.winuser32.SetWindowPlacement(hwnd,ctypes.byref(wtp)) 462 | elif flag == 7: 463 | wtp = WINDOWPLACEMENT() 464 | is_ok = DMWindow.winuser32.GetWindowPlacement(hwnd,ctypes.byref(wtp)) 465 | wtp.showCmd = 5 466 | is_ok = DMWindow.winuser32.SetWindowPlacement(hwnd,ctypes.byref(wtp)) 467 | elif flag == 8: 468 | is_ok = DMWindow.winuser32.SetWindowPos(hwnd,-1,0,0,0,0,3) 469 | elif flag == 9: 470 | is_ok = DMWindow.winuser32.SetWindowPos(hwnd,-2,0,0,0,0,3) 471 | elif flag in [10,11,12]: 472 | pass 473 | elif flag == 13: 474 | pid = DMWindow.GetWindowProcessId(hwnd) 475 | hProcessHandle = DMWindow.winKernel32.OpenProcess(1, False, pid) 476 | is_ok = DMWindow.winKernel32.TerminateProcess(hProcessHandle,4) 477 | DMWindow.winKernel32.CloseHandle(hProcessHandle) 478 | elif flag == 14: 479 | is_ok = DMWindow.winuser32.FlashWindow(hwnd,True) 480 | elif flag == 15: 481 | hCurWnd = DMWindow.winuser32.GetForegroundWindow() 482 | dwMyID = DMWindow.winKernel32.GetCurrentThreadId() 483 | dwCurID = DMWindow.winuser32.GetWindowThreadProcessId(hCurWnd, 0) 484 | DMWindow.winuser32.AttachThreadInput(dwCurID, dwMyID, True) 485 | is_ok = DMWindow.winuser32.SetFocus(hwnd) 486 | DMWindow.winuser32.AttachThreadInput(dwCurID, dwMyID, False) 487 | if not is_ok: 488 | raise Exception('call SetWindowState failed') 489 | @staticmethod 490 | def EnumWindow(parent_,title,class_name,filter): 491 | if not parent_: 492 | parent_ = DMWindow.GetSpecialWindow(0) 493 | martchVec = [] 494 | def mycallback(hwnd,extra) -> bool: 495 | wtitle = None 496 | wclass = None 497 | try: 498 | wtitle = DMWindow.GetWindowTitle(hwnd) 499 | wclass = DMWindow.GetWindowClass(hwnd) 500 | except: 501 | return True 502 | if filter & 1 == 1: 503 | if title.upper() not in wtitle.upper(): 504 | return True 505 | if ((filter & 2)>>1) == 1: 506 | if class_name.upper() not in wclass.upper(): 507 | return True 508 | if ((filter & 4)>>2) == 1: 509 | try: 510 | if DMWindow.GetWindow(hwnd,0) != parent_: 511 | return True 512 | except: 513 | return True 514 | if ((filter & 8)>>3) == 1: 515 | if not (DMWindow.winuser32.GetParent(hwnd) == 0): 516 | return True 517 | if DMWindow.winKernel32.GetLastError() != 0: 518 | return True 519 | if ((filter & 16)>>4) == 1: 520 | if DMWindow.GetWindowState(2) == False: 521 | return True 522 | martchVec.append(hwnd) 523 | return True 524 | CMPFUNC = ctypes.WINFUNCTYPE(ctypes.wintypes.BOOL,ctypes.wintypes.HWND, ctypes.wintypes.LPARAM) 525 | DMWindow.winuser32.EnumChildWindows(parent_,CMPFUNC(mycallback),0) 526 | if len(martchVec) == 0: 527 | raise Exception('call EnumWindow failed:not found any window') 528 | return ','.join([str(i) for i in martchVec]) 529 | --------------------------------------------------------------------------------