#coding=utf-8
import sys
import getopt
import pyautogui


MOUSE_MOVE_DISTANCE = 20;           # 定义鼠标单次移动距离，可修改
MOUSE_LONG_MOVE_DISTANCE = 20;      # 定义鼠标持续移动距离, 可修改



pyautogui.FAILSAFE = False

if __name__ == "__main__":
    args = sys.argv  # 获取命令行参数
    if len(args) != 2:
        raise IndexError("参数个数不正确！")
    opts,args = getopt.getopt(sys.argv[1:], '-h',
            ['Mright', 'Mleft', 'Mup', 'Mdown','Mleftclick',
             'MLup', 'MLdown', 'MLright', 'MLleft',
             'Kup', 'Kdown', 'KPageup', 'KPagedown',
             'Custom_Key_1', 'Custom_Key_2', 'Custom_Key_3',
             'Custom_Key_4', 'Custom_Key_5', 'Custom_Key_6'])
    
    # Mxx  鼠标   Kxx 键盘
for opt_name, opt_value in opts:
    if opt_name in ('--Mright'):
#        pyautogui.moveRel(int(args[1]), int(args[2]), duration=float(args[3]))
        pyautogui.moveRel( MOUSE_MOVE_DISTANCE, 0, duration=0.1)
        exit()

    if opt_name in ('--Mleft'):
        pyautogui.moveRel( -MOUSE_MOVE_DISTANCE, 0, duration=0.1)
        exit()
    
    if opt_name in ('--Mup'):
        pyautogui.moveRel( 0, -MOUSE_MOVE_DISTANCE, duration=0.1)
        exit()

    if opt_name in ('--Mdown'):
        pyautogui.moveRel( 0, MOUSE_MOVE_DISTANCE, duration=0.1)
        exit()
    
    if opt_name in ('--MLup'):
        while 1:
            pyautogui.moveRel( 0, -MOUSE_LONG_MOVE_DISTANCE, duration=0)
        exit()
    
    if opt_name in ('--MLdown'):
        while 1:
            pyautogui.moveRel( 0, MOUSE_LONG_MOVE_DISTANCE, duration=0)
        exit()
    
    if opt_name in ('--MLright'):
        while 1:
            pyautogui.moveRel( MOUSE_LONG_MOVE_DISTANCE, 0, duration=0)
        exit()
    
    if opt_name in ('--MLleft'):
        while 1:
            pyautogui.moveRel( -MOUSE_LONG_MOVE_DISTANCE, 0, duration=0)
        exit()

    if opt_name in ('--Mleftclick'):
        pyautogui.click( )
        exit()
    
    if opt_name in ('--Kup'):
        #pyautogui.click( )
        pyautogui.scroll('1')
        pyautogui.press('up')
        exit()

    if opt_name in ('--Kdown'):
        #pyautogui.click( )
        pyautogui.scroll('-1')
        pyautogui.press('down')
        exit()

    if opt_name in ('--KPageup'):
        #pyautogui.click( )
        pyautogui.scroll('1')
        pyautogui.press('pageup')
        exit()

    if opt_name in ('--KPagedown'):
        #pyautogui.click( )
        pyautogui.scroll('-1')
        pyautogui.press('pagedown')
        exit()

###### custom key 1-6 #########
# 根据 pyautogui 使用方式， 自定义以下按键的功能。
    if opt_name in ('--Custom_Key_1'):
        pyautogui.click( button = 'right')
        exit()

    if opt_name in ('--Custom_Key_2'):
        pyautogui.click( button = 'right') 
        exit()

    if opt_name in ('--Custom_Key_3'):
        pyautogui.click( button = 'right')
        exit()

    if opt_name in ('--Custom_Key_4'):
        pyautogui.click( button = 'right')
        exit()

    if opt_name in ('--Custom_Key_5'):
        pyautogui.click( button = 'right')
        exit()

    if opt_name in ('--Custom_Key_6'):
        pyautogui.click( button = 'right')
        exit()

