精华内容
下载资源
问答
  • 在c 语言里,用 win32 api 创建的一个窗口,里面有两个输入文本框: CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "hello", WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL|WS_TABSTOP, 98, // xpos 69, // ypos ...
  • The Win32 API, or Application Programming Interface, is of immense use in extending the power of Visual Basic. The Win32 API is the collection of functions and subroutines that provides programmatic ...
  • ## 背景:拦截windows系统键盘输出,通过组合键设置,将常用的操作、需要打开的程序、文件,简化为两次按键## 已实现的功能对于普遍用户来说,这个小工具最受欢迎的功能应该是Tab+g了,它可以在你在电脑的任何地方,...

    ## Mykeyboard你的键盘精灵!

    ## 背景:

    拦截windows系统键盘输出,通过组合键设置,将常用的操作、需要打开的程序、文件,简化为两次按键

    ## 已实现的功能

    对于普遍用户来说,这个小工具最受欢迎的功能应该是Tab+g了,它可以在你在电脑的任何地方,比如和姑娘的微信聊天窗口,按一下Tab,再按一下g,立马就能让你转到百度搜索,马上就能搜出一大堆多喝热水的好处^_^。又比如tab+y,快速打开有道翻译,tab+t,快速打开记事本。

    在此就不一一详述了,可以看下方截图说明

    **重要的事说三遍**

    该软件所有快捷方式,均为按下tab键,松开后再按其他键,而非同时按键!!!

    该软件所有快捷方式,均为按下tab键,松开后再按其他键,而非同时按键!!!

    该软件所有快捷方式,均为按下tab键,松开后再按其他键,而非同时按键!!!

    目前不支持自定义、有需求可单独联系

    ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190512165133113.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjEyOTI0OA==,size_16,color_FFFFFF,t_70)

    ## 2019.10.21更新说明

    修复在hbuildX等带提示的软件环境下,部分快捷失效情境

    新增自定义快速打开文件及软件功能:

    1. 新增三组快捷方式Tab + W、Tab + A、Tab + H,分别对应w.bat、any.bat、h.bat;

    2. 自定义快速打开应用程序, 以w.bat为例,右键选中编辑打开(不可直接双击打开),其内容如下:

    `start "" "C:\Users\Administrator\AppData\Local\Kingsoft\WPS Office\ksolaunch.exe"

    //将路径地址更改为自己的应用地址即可`

    3. 自定义快速打开文件,以any.bat为例,打开可看见如下内容

    `start "" "C:\Users\Administrator\Desktop\我是word.doc"

    //将路径更换为自己的文件路径即可,不限格式

    `

    ## 2019.08.26更新说明

    修复对系统原有快捷方式alt + table、shift + table的影响;

    设置开机自启动的方法:https://blog.csdn.net/weixin_42129248/article/details/100087913

    ## 2019.07.21更新说明

    由于在linux下会大量使用tab键,为了应对该场景,设置了tab+q暂停工具设置的快捷功能,消除对tab键原有功能的影响,再次按下tab + q,即可恢复软件功能

    ## 下载链接:

    1. 在我的csdn中下载

    2. 加微信免费获取:微信号mk114302

    源码地址:https://github.com/MusiCoder32/MyKeyboard

    展开全文
  • python的win32操作

    2015-08-08 02:57:00
    ## _*_ coding:UTF-8 _*___author__ = 'shanl'import win32apiimport win32conimport win32guifrom ctypes import *import timeVK_CODE = { 'backspace':0x08, 'tab':0x09, 'clear':0x0C, 'enter':...
    #
    # _*_ coding:UTF-8 _*_
    __author__ = 'shanl'
    import win32api
    import win32con
    import win32gui
    from ctypes import *
    import time
    VK_CODE = {
    'backspace':0x08,
    'tab':0x09,
    'clear':0x0C,
    'enter':0x0D,
    'shift':0x10,
    'ctrl':0x11,
    'alt':0x12,
    'pause':0x13,
    'caps_lock':0x14,
    'esc':0x1B,
    'spacebar':0x20,
    'page_up':0x21,
    'page_down':0x22,
    'end':0x23,
    'home':0x24,
    'left_arrow':0x25,
    'up_arrow':0x26,
    'right_arrow':0x27,
    'down_arrow':0x28,
    'select':0x29,
    'print':0x2A,
    'execute':0x2B,
    'print_screen':0x2C,
    'ins':0x2D,
    'del':0x2E,
    'help':0x2F,
    '0':0x30,
    '1':0x31,
    '2':0x32,
    '3':0x33,
    '4':0x34,
    '5':0x35,
    '6':0x36,
    '7':0x37,
    '8':0x38,
    '9':0x39,
    'a':0x41,
    'b':0x42,
    'c':0x43,
    'd':0x44,
    'e':0x45,
    'f':0x46,
    'g':0x47,
    'h':0x48,
    'i':0x49,
    'j':0x4A,
    'k':0x4B,
    'l':0x4C,
    'm':0x4D,
    'n':0x4E,
    'o':0x4F,
    'p':0x50,
    'q':0x51,
    'r':0x52,
    's':0x53,
    't':0x54,
    'u':0x55,
    'v':0x56,
    'w':0x57,
    'x':0x58,
    'y':0x59,
    'z':0x5A,
    'numpad_0':0x60,
    'numpad_1':0x61,
    'numpad_2':0x62,
    'numpad_3':0x63,
    'numpad_4':0x64,
    'numpad_5':0x65,
    'numpad_6':0x66,
    'numpad_7':0x67,
    'numpad_8':0x68,
    'numpad_9':0x69,
    'multiply_key':0x6A,
    'add_key':0x6B,
    'separator_key':0x6C,
    'subtract_key':0x6D,
    'decimal_key':0x6E,
    'divide_key':0x6F,
    'F1':0x70,
    'F2':0x71,
    'F3':0x72,
    'F4':0x73,
    'F5':0x74,
    'F6':0x75,
    'F7':0x76,
    'F8':0x77,
    'F9':0x78,
    'F10':0x79,
    'F11':0x7A,
    'F12':0x7B,
    'F13':0x7C,
    'F14':0x7D,
    'F15':0x7E,
    'F16':0x7F,
    'F17':0x80,
    'F18':0x81,
    'F19':0x82,
    'F20':0x83,
    'F21':0x84,
    'F22':0x85,
    'F23':0x86,
    'F24':0x87,
    'num_lock':0x90,
    'scroll_lock':0x91,
    'left_shift':0xA0,
    'right_shift ':0xA1,
    'left_control':0xA2,
    'right_control':0xA3,
    'left_menu':0xA4,
    'right_menu':0xA5,
    'browser_back':0xA6,
    'browser_forward':0xA7,
    'browser_refresh':0xA8,
    'browser_stop':0xA9,
    'browser_search':0xAA,
    'browser_favorites':0xAB,
    'browser_start_and_home':0xAC,
    'volume_mute':0xAD,
    'volume_Down':0xAE,
    'volume_up':0xAF,
    'next_track':0xB0,
    'previous_track':0xB1,
    'stop_media':0xB2,
    'play/pause_media':0xB3,
    'start_mail':0xB4,
    'select_media':0xB5,
    'start_application_1':0xB6,
    'start_application_2':0xB7,
    'attn_key':0xF6,
    'crsel_key':0xF7,
    'exsel_key':0xF8,
    'play_key':0xFA,
    'zoom_key':0xFB,
    'clear_key':0xFE,
    '+':0xBB,
    ',':0xBC,
    '-':0xBD,
    '.':0xBE,
    '/':0xBF,
    '`':0xC0,
    ';':0xBA,
    '[':0xDB,
    '\\':0xDC,
    ']':0xDD,
    "'":0xDE,
    '`':0xC0}
    class POINT(Structure):
    _fields_ = [("x", c_ulong),("y", c_ulong)]

    def get_mouse_point():
    po = POINT()
    windll.user32.GetCursorPos(byref(po))
    return int(po.x), int(po.y)

    def mouse_click(x=None,y=None):
    if not x is None and not y is None:
    mouse_move(x,y)
    time.sleep(0.05)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)

    def mouse_dclick(x=None,y=None):
    if not x is None and not y is None:
    mouse_move(x,y)
    time.sleep(0.05)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)

    def mouse_move(x,y):
    windll.user32.SetCursorPos(x, y)

    def key_input(str=''):
    for c in str:
    win32api.keybd_event(VK_CODE[c],0,0,0)
    win32api.keybd_event(VK_CODE[c],0,win32con.KEYEVENTF_KEYUP,0)
    time.sleep(0.01)
    def t0():
    pass

    def t2():
    mouse_click(800,200)
    for c in 'hello':
    win32api.keybd_event(65,0,0,0) #a键位码是86
    win32api.keybd_event(65,0,win32con.KEYEVENTF_KEYUP,0)
    #print get_mouse_point()
    def t1():
    #mouse_move(1024,470)aa
    #time.sleep(0.05)
    #mouse_dclick()HELLO
    mouse_dclick(1024,470)
    def t3():
    mouse_click(1024,470)
    str = 'hello'
    for c in str:
    win32api.keybd_event(VK_CODE[c],0,0,0) #a键位码是86
    win32api.keybd_event(VK_CODE[c],0,win32con.KEYEVENTF_KEYUP,0)
    time.sleep(0.01)
    def t4():
    mouse_click(1024,470)
    str = 'hello'
    key_input(str)
    if __name__ == "__main__":
    #t4()
    t3()
    #t2()
    #t1()
    t0()
     
     
    还可以看看
    http://blog.csdn.net/xm1331305/article/details/8090347
    http://www.linuxidc.com/Linux/2011-12/48525.htm
     
    win32库在
    http://sourceforge.net/projects/pywin32/files/?source=navbar
    可以下载

    转载于:https://www.cnblogs.com/elautoctrl/p/4712395.html

    展开全文
  • //DLL文件//GHook.cpp#define _WIN32_WINNT 0x0400#include #include "HookAPI.h"#include typedef HANDLE (_stdcall *OPENPROCESS_PROC)(DWORD, BOOL, DWORD);OPENPROCESS_PROC pOpenProcess = NULL;HWND g_h

    //DLL文件

    //GHook.cpp

    #define _WIN32_WINNT 0x0400
    #include <windows.h>
    #include "HookAPI.h"
    #include <Tlhelp32.h>

    typedef HANDLE (_stdcall *OPENPROCESS_PROC)(DWORD, BOOL, DWORD);

    OPENPROCESS_PROC pOpenProcess = NULL;
    HWND g_hWnd;
    HHOOK g_hHook;
    HINSTANCE g_hInst;
    HHOOK g_hHook_Key;
    _declspec(dllexport) LRESULT CALLBACK HookKeyDownProc(int nCode,WPARAM wParam,LPARAM lParam);
    DWORD FindProcessId(const char* name);
    _declspec(dllexport) LRESULT CALLBACK  HookFunction(int code, WPARAM wParam, LPARAM lParam);
    HANDLE _stdcall OpenProcess_Handler(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId)
    {
     HANDLE RetValue = NULL;
     DWORD ProcessId;

     ProcessId=FindProcessId("ProcessID.exe");  //ProcessID.exe为欲防杀的进程名
     if (dwProcessId != ProcessId)
     {    //此处代码,未严加推敲,但防止了任务管理器出错,原因待查。
      UnhookWindowsHookEx(g_hHook);
      RetValue = pOpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId);
      g_hHook=SetWindowsHookEx(WH_SYSMSGFILTER,HookFunction,g_hInst,0);
     } 
     return RetValue;
    }
    //_declspec(dllexport) LRESULT CALLBACK  HookFunction(int code, WPARAM wParam, LPARAM lParam)
    {
     if (pOpenProcess == NULL)
      pOpenProcess = (OPENPROCESS_PROC)HookAPIFunction(GetModuleHandle(NULL), "KERNEL32.DLL", "OpenProcess", (PROC)OpenProcess_Handler);
     return CallNextHookEx(g_hHook,code,wParam,lParam);
    // return FALSE;
    }


    BOOL WINAPI DllMain(/*HANDLE*/HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved)
    {
    /* switch (dwReason)
     {
     case DLL_PROCESS_ATTACH:
      DisableThreadLibraryCalls(hInst);
      break;
     }*/
     g_hInst=hInst;
     return true;
    }
    //砞竚秈祘ň炳筥
    extern "C" _declspec(dllexport) void  _stdcall SetHook(HWND temphWnd)
    {
     g_hWnd=temphWnd;
     g_hHook=SetWindowsHookEx(WH_SYSMSGFILTER,HookFunction,g_hInst,0);
    }
    //闽超秈祘ň炳筥
    extern "C" _declspec(dllexport) void _stdcall  UnHook()
    {
     UnhookWindowsHookEx(g_hHook);
    }

    //砞竚龄絃龄筥
    extern "C" _declspec(dllexport) void _stdcall SetHook_Key()
    {
     g_hHook_Key=SetWindowsHookEx(WH_KEYBOARD_LL,HookKeyDownProc,g_hInst,0);
    }
    //
    extern "C" _declspec(dllexport) void _stdcall UnHook_Key()
    {
     UnhookWindowsHookEx(g_hHook_Key);
    }

    //
    _declspec(dllexport) LRESULT CALLBACK HookKeyDownProc(int nCode,WPARAM wParam,LPARAM lParam)
    {
    /* if(VK_F4==wParam && (1==(lParam>>29 & 1)))
      return 1;
     if(VK_TAB==wParam && (1==(lParam>>29 & 1)))
      return 1;
     if(VK_LWIN==wParam || VK_RWIN == wParam)
      return 1;
     if(VK_RETURN==wParam)
      return 1;
     return CallNextHookEx(g_hHook_Key,nCode,wParam,lParam);*/
     BOOL fEatKeystroke = FALSE;
        PKBDLLHOOKSTRUCT p = NULL; 
        if (nCode == HC_ACTION)
        {
            p = (PKBDLLHOOKSTRUCT) lParam;
            switch (wParam)
            {
      case WM_KEYDOWN:
       // Backdoor to user information
       if (p->vkCode == VK_F8)
       {
        ::MessageBox(NULL,"Apple Net Coffee Management System/n","Apple",MB_OK);
        break;
       }
      case WM_SYSKEYDOWN:
      case WM_KEYUP:   
      case WM_SYSKEYUP:
       fEatKeystroke =
        (p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN) ||  // 姜Win
        // 姜Alt+Tab
        ((p->vkCode == VK_TAB) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
        //ALT+f4
    //    ((p->vkCode == VK_F4) && ((p->flags & LLKHF_ALTDOWN) != 0))||
        // 姜Alt+Esc
        ((p->vkCode == VK_ESCAPE) && ((p->flags & LLKHF_ALTDOWN) != 0)) ||
        // 姜Ctrl+Esc
        ((p->vkCode == VK_ESCAPE) && ((GetKeyState(VK_CONTROL) & 0x8000) != 0));
       break;
      default:
       break;
      }
        } 
     return (fEatKeystroke ? TRUE : CallNextHookEx(g_hHook_Key,nCode,wParam,lParam));
    }

    DWORD FindProcessId(const TCHAR *name) //琩т秈祘
    {
     DWORD  dwID = 0; 
        HANDLE m_handle = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); 
        PROCESSENTRY32* Info = new PROCESSENTRY32; 
        Info->dwSize = sizeof(PROCESSENTRY32); 
        BOOL bFind = Process32First(m_handle, Info); 
        while (bFind)
        {  
      if(stricmp(Info->szExeFile,name)==0)
      {  
       
                dwID = Info->th32ProcessID;   
                bFind = FALSE;   
                break;   
            }  
            bFind = Process32Next(m_handle, Info);  
        }  
        delete Info; 
        Info = NULL; 
        CloseHandle(m_handle); 
        return dwID;

     

    //Hookapi.cpp


    // -----------------------------
    //  HOOKAPI - Matt Pietrek 1995
    // -----------------------------

    #include <windows.h>
    #include "HookAPI.h"

    // Macro for adding pointers/DWORDs together without C arithmetic interfering

    #define MakePtr(cast, ptr, addValue) (cast)((DWORD)(ptr)+(DWORD)(addValue))

    PROC HookAPIFunction(HMODULE hFromModule,
                         PSTR pszFunctionModule,
                         PSTR pszFunctionName,
                         PROC pfnNewProc)
    {
     PROC pfnOriginalProc;
     PIMAGE_DOS_HEADER pDosHeader;
     PIMAGE_NT_HEADERS pNTHeader;
     PIMAGE_IMPORT_DESCRIPTOR pImportDesc;
     PIMAGE_THUNK_DATA pThunk;
     
     DWORD dwProtectionFlags;
     DWORD dwScratch;
     
     // Verify that a valid pfn was passed 
     if (IsBadCodePtr(pfnNewProc)) return 0;   
     // First, verify the the module and function names passed to use are valid 
     pfnOriginalProc = GetProcAddress(GetModuleHandle(pszFunctionModule), pszFunctionName); 
     if (!pfnOriginalProc) return 0; 
     pDosHeader = (PIMAGE_DOS_HEADER)hFromModule; 
     // Tests to make sure we're looking at a module image (the 'MZ' header) 
     if (IsBadReadPtr(pDosHeader, sizeof(IMAGE_DOS_HEADER))) return 0; 
     if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) return 0; 
     // The MZ header has a pointer to the PE header 
     pNTHeader = MakePtr(PIMAGE_NT_HEADERS, pDosHeader, pDosHeader->e_lfanew); 
     // More tests to make sure we're looking at a "PE" image 
     if (IsBadReadPtr(pNTHeader, sizeof(IMAGE_NT_HEADERS))) return 0; 
     if (pNTHeader->Signature != IMAGE_NT_SIGNATURE) return 0; 
     // We know have a valid pointer to the module's PE header.
     // Now go get a pointer to its imports section 
     pImportDesc = MakePtr(PIMAGE_IMPORT_DESCRIPTOR, pDosHeader,
      pNTHeader->OptionalHeader.
      DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].
      VirtualAddress); 
     // Bail out if the RVA of the imports section is 0 (it doesn't exist) 
     if (pImportDesc == (PIMAGE_IMPORT_DESCRIPTOR)pNTHeader) return 0; 
     // Iterate through the array of imported module descriptors, looking
     // for the module whose name matches the pszFunctionModule parameter 
     while (pImportDesc->Name)
     {
      PSTR pszModName = MakePtr(PSTR, pDosHeader, pImportDesc->Name);      
      if (stricmp(pszModName, pszFunctionModule) == 0) break;  
      // Advance to next imported module descriptor  
      pImportDesc++;
     } 
     // Bail out if we didn't find the import module descriptor for the
     // specified module.  pImportDesc->Name will be non-zero if we found it. 
     if (pImportDesc->Name == 0) return 0; 
     // Get a pointer to the found module's import address table (IAT) 
     pThunk = MakePtr(PIMAGE_THUNK_DATA, pDosHeader, pImportDesc->FirstThunk); 
     // Blast through the table of import addresses, looking for the one
     // that matches the address we got back from GetProcAddress above. 
     while (pThunk->u1.Function)
     {
      if (pThunk->u1.Function == (PDWORD)pfnOriginalProc)
      {
       dwProtectionFlags = PAGE_READWRITE;   
       VirtualProtect(&pThunk->u1.Function, 4096, dwProtectionFlags, &dwScratch);   
       // We found it!  Overwrite the original address with the
       // address of the interception function.  Return the original
       // address to the caller so that they can chain on to it.   
       pThunk->u1.Function = (PDWORD)pfnNewProc;   
       return pfnOriginalProc;
      }       
      // Advance to next imported function address  
      pThunk++;
     }  
     // Function not found 
     return 0;
    }

     

    //Hookapi.h

    #ifndef HOOKAPI_H
    #define HOOKAPI_H

    PROC HookAPIFunction(HMODULE hFromModule,
                         PSTR pszFunctionModule,
                         PSTR pszFunctionName,
                         PROC pfnNewProc);

    #endif

    展开全文
  • #encoding=utf-8 import unittest from selenium import webdriver ...import win32api, win32con VK_CODE ={'ctrl':0x11, 't':0x54, 'tab':0x09} # 键盘键按下 def keyDown(keyName): win32a...
    #encoding=utf-8
    import unittest
    from selenium import webdriver
    import time
    import win32api, win32con
    
    VK_CODE ={'ctrl':0x11, 't':0x54, 'tab':0x09}
    
    # 键盘键按下
    def keyDown(keyName):
        win32api.keybd_event(VK_CODE[keyName], 0, 0, 0)
    # 键盘键抬起
    def keyUp(keyName):
        win32api.keybd_event(VK_CODE[keyName], 0, win32con.KEYEVENTF_KEYUP, 0)
    
    # 封装的按键方法
    def simulateKey(firstKey, secondKey):
        keyDown(firstKey)
        keyDown(secondKey)
        keyUp(secondKey)
        keyUp(firstKey)
    
    class TestDemo(unittest.TestCase):
        def setUp(self):
            # 获取浏览器驱动实例
            self.driver = webdriver.Ie(executable_path = "e:\\IEDriverServer")
            #self.driver = webdriver.Firefox(executable_path = "e:\\geckodriver")
        def test_newTab(self):
            # 等待3秒,等待浏览器启动完成
            time.sleep(3)
            # 使用for循环,再新开两个新的标签页
            for i in range(2):
                simulateKey("ctrl", "t")
            # 通过Ctrl + tab组合键,将当前页面切换为默认页面,
            # 也就是最先打开的标签页
            simulateKey("ctrl", "tab")
            # 访问搜狗首页
            self.driver.get("http://sogou.com")
            self.driver.find_element_by_id("query").send_keys(u"光荣之路")
            self.driver.find_element_by_id("stb").click()
            time.sleep(3)
            #self.assertTrue(u"乔什•卢卡斯" in self.driver.page_source)
    
            # 获取所有的打开的窗口句柄
            all_handles = self.driver.window_handles
            print len(all_handles)
            for handle in all_handles:
                # 将当前窗口句柄切换至第二个标签页
                self.driver.switch_to.window(handle)
                print self.driver.title
                if u"输入法" not in self.driver.page_source:
                    self.driver.get("http://www.baidu.com")
                    self.driver.find_element_by_id("kw").send_keys(u"WebDriver实战宝典")
                    self.driver.find_element_by_id("su").click()
                    time.sleep(3)
                    self.assertTrue(u"实战宝典" in self.driver.page_source)
                elif (u"输入法" not in self.driver.page_source) and ("WebDriver" not in self.driver.page_source):
                # 将当前窗口的句柄切换至第三个标签页
                    self.driver.get("http://www.iciba.com")
                    time.sleep(3)
                    self.assertTrue(u"查词" in self.driver.page_source)
    
        def tearDown(self):
            # 退出浏览器
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()

     

    基于火狐:

    #encoding=utf-8
    import unittest
    from selenium import webdriver
    import time
    import win32api, win32con
    
    VK_CODE ={'ctrl':0x11, 't':0x54, 'tab':0x09}
    
    # 键盘键按下
    def keyDown(keyName):
        win32api.keybd_event(VK_CODE[keyName], 0, 0, 0)
    # 键盘键抬起
    def keyUp(keyName):
        win32api.keybd_event(VK_CODE[keyName], 0, win32con.KEYEVENTF_KEYUP, 0)
    
    # 封装的按键方法
    def simulateKey(firstKey, secondKey):
        keyDown(firstKey)
        keyDown(secondKey)
        keyUp(secondKey)
        keyUp(firstKey)
    
    class TestDemo(unittest.TestCase):
        def setUp(self):
            # 获取浏览器驱动实例
            #self.driver = webdriver.Ie(executable_path = "e:\\IEDriverServer")
            self.driver = webdriver.Firefox(executable_path = "e:\\geckodriver")
        def test_newTab(self):
            # 等待3秒,等待浏览器启动完成
            time.sleep(3)
            # 使用for循环,再新开两个新的标签页
            for i in range(2):
                simulateKey("ctrl", "t")
            # 通过Ctrl + tab组合键,将当前页面切换为默认页面,
            # 也就是最先打开的标签页
            simulateKey("ctrl", "tab")
            # 访问搜狗首页
            self.driver.get("http://sogou.com")
            self.driver.find_element_by_id("query").send_keys(u"光荣之路")
            self.driver.find_element_by_id("stb").click()
            time.sleep(3)
            #self.assertTrue(u"乔什•卢卡斯" in self.driver.page_source)
    
            # 获取所有的打开的窗口句柄
            all_handles = self.driver.window_handles
            print len(all_handles)
            # 将当前窗口句柄切换至第二个标签页
            self.driver.switch_to.window(all_handles[1])
            self.driver.get("http://www.baidu.com")
            self.driver.find_element_by_id("kw").send_keys(u"WebDriver实战宝典")
            self.driver.find_element_by_id("su").click()
            time.sleep(3)
            self.assertTrue(u"吴晓华" in self.driver.page_source)
    
            # 将当前窗口的句柄切换至第三个标签页
            self.driver.switch_to.window(all_handles[2])
            self.driver.get("http://www.baidu.com")
            self.driver.find_element_by_id("kw").send_keys("selenium")
            self.driver.find_element_by_id("su").click()
            time.sleep(3)
            self.assertTrue("www.seleniumhq.org" in self.driver.page_source)
    
        def tearDown(self):
            # 退出浏览器
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()

     

    转载于:https://www.cnblogs.com/qingqing-919/p/8716576.html

    展开全文
  • pywin32的使用

    2020-09-15 14:06:23
    import win32api,win32gui,win32con, win32com.client, win32clipboard import pythoncom import os import time from enum import Enum # 键盘按键对应代码 VK_CODE = {'backspace': 0x08, 'tab': 0x09, 'clear'...
  • <div><p>Running <code>malboxes build win7_32_analyst</code> fails during the installation of <code>.NET Framework 4.0</code>. Here are the relevant logs : <pre><code> ==> virtualbox-iso: ...
  • Pywin32 使用Demo键盘输入与鼠标点击

    千次阅读 2019-01-04 19:55:23
    import win32api,win32gui,win32con import os import time class WindowUtils(): VK_CODE = {'backspace': 0x08, 'tab': 0x09, 'clear': 0x0C, 'enter': 0x0D,...
  • 模拟按键-pywin32-包含

    2019-06-15 10:28:00
    ## _*_ coding:UTF-8 _*_import win32apiimport win32conimport win32guiimport ctypesfrom ctypes import *import timeVK_CODE = { 'backspace':0x08, 'tab':0x09, 'clear':0x0C, 'enter':0x0D, 'shift':0x10,...
  • 此代码示范并解释了如何用纯粹的API创建窗口控件,如使用CreateWindow和 CreateWindowEx在窗口中创建列表框、编辑框和按钮。...关键字:control,win32,api,listctrl,edit,button,列表框,编辑框,按钮
  • <p>Interestingly, on Windows it already breaks at linking, see the end of http://nightly.geany.org/win32/build_win32_plugins_stderr.log.</p> <p>Does anyone have an idea if anything has changed ...
  • # _*_ coding:UTF-8 _*_import win32apiimport win32con#import win32gui#from ctypes import *import ctypesimport timeVK_CODE = {'backspace':0x08,'tab':0x09,'clear':0x0C,'enter':0x0D,'shift':0x10,'ctrl':0x...
  • Windows SDK设置控件支持Tab

    千次阅读 2013-08-29 10:38:41
    我在使用codeblocks写Win32GUI工程时,建立了一个Frame Based的项目,然后进行编程,创建了一堆的Edit控件,代码如下: Hwnd_EDIT_Set_IP=CreateWindow(TEXT("EDIT"),TEXT(""),WS_CHILD | WS_BOR
  • <p>https://www.programcreek.com/python/example/82687/win32api.GetVolumeInformation</p> <p>Just for grins I applied a registry edit to enable long paths. It did not work after a reboot. This did ...
  • 1.先定义一个类,以调用API (注:要按顺序先...private class Win32Helper //创建个类 {  public const int KEYEVENTF_KEYUP = 0x0002;  [DllImport("coredll.dll")]  public static extern void keybd_event
  • tab shows "loading files" but never changes. Eventually, after several hours, Sia client takes all RAM and runs the HD up to 100% making the computer impossible to use. <p>Sia Daemon v1.3.1 ...
  • 通过调用Win32 API函数SystemParametersInfo ,你可以关闭Windows的CTRL+ALT+DEL 和 ALT+TAB key热键。 但出于安全考虑,Microsoft并未提供该函数关于关闭上述热键方法的介绍。但实际上要实现这个...
  • After I use pip comand the nbextensions, there is a tab 'nbextensions' in the dashboard of jupyter notebook, but it is empty. the error messages are as following: <pre><code> Copy/paste this ...
  • <div><p>GoldenCheetah consistently crashes whenever I try to view the Ride tab. <img alt="errormessage" src="https://img-blog.csdnimg.cn/img_convert/ef2b9c88833a9a15b0e6fd2b8a8ca92b.png" /></p> <p>...
  • Effectively making the application window behave like a Win32 window that's in fullscreen-windowed mode. <p><strong>ApplicationView.FullsScreenOverlayMode.None</strong></p> <p>Thanks to weltkante...
  • <p><img alt="win7 start running - oracle vm virtualbox_101" src="https://img-blog.csdnimg.cn/img_convert/4b2c02b2361fcea35410e916a8d36ad3.png" /></p> <h4>beta5 on Ubuntu 16.10 VM <p>Fresh PEX run, ...
  • 0x7c [e:\src\dr\git\src\core\win32\ntdll.c @ 3296] 02 1d7435bc 00aebf29 dynamorio!debugbox+0x71 [e:\src\dr\git\src\core\win32\os.c @ 3431] 03 1d743b2c 00aed5f7 dynamorio!notify+0xd9 [e...
  • ## _*_ coding:UTF-8 _*_import win32apiimport win32conimport win32guifrom ctypes import *import timeimport win32clipboardfrom PIL import Image, ImageGrabVK_CODE = {'backspace':0x08,'tab':0x09,'clear':0...
  • import win32api, win32con K_CODE = {‘ctrl’:0x11, ‘t’:0x54, ‘tab’:0x09} 按下键盘 def keyDown(keyName): win32api.keybd_event(K_CODE[keyName],0,0,0) 抬起键盘 def keyUP(keyName): win32api.keyb
  • Python screen onclick

    2017-11-23 18:16:00
    import win32api import win32con import win32gui from ctypes import * import time VK_CODE = { 'backspace':0x08, 'tab':0x09, 'clear':0x0C, 'enter':0x0D, 'shift':0x10, ...
  • # # _*_ coding:UTF-8 _*_ import win32api import win32con import win32gui import time import webbrowser from ctypes import * import time VK_CODE = {  'backspace':0x08,  'tab':0x09,  'cle
  • import win32api import win32con import win32gui from ctypes import * import time VK_CODE = { 'backspace':0x08, 'tab':0x09, 'clear':0x0C, 'enter':0x0D, 'shift':0x10, 'ctrl':0x1...

空空如也

空空如也

1 2 3 4 5 ... 9
收藏数 161
精华内容 64
关键字:

apitabwin32