Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
Last active August 24, 2019 16:06
Show Gist options
  • Save snipsnipsnip/1101192 to your computer and use it in GitHub Desktop.
Save snipsnipsnip/1101192 to your computer and use it in GitHub Desktop.
win32guitest.rb
# jun hirabayashi jun@hirax.net 2008.11.15-2011.07.12
# merged into a single file, and put constants into Win32GuiTest::Constants
require 'Win32API'
require 'win32ole'
require 'dl/win32'
require 'dl/import'
class Win32GuiTest
# from win32_office_defines.rb
module Constants
MOUSEEVENTF_ABSOLUTE = 0x8000
MOUSEEVENTF_MOVE = 0x1
MOUSEEVENTF_LEFTDOWN = 0x2
MOUSEEVENTF_LEFTUP = 0x4
MOUSEEVENTF_RIGHTDOWN = 0x8
MOUSEEVENTF_RIGHTUP = 0x10
MOUSEEVENTF_MIDDLEDOWN = 0x20
MOUSEEVENTF_MIDDLEUP = 0x40
MOUSEEVENTF_XDOWN=0x100
MOUSEEVENTF_XUP=0x200
MOUSEEVENTF_WHEEL=0x80
WM_MOUSEMOVE=0x0200
WM_LBUTTONDOWN=0x0201
WM_LBUTTONUP=0x0202
WM_LBUTTONDBLCLK=0x0203
WM_RBUTTONDOWN=0x0204
WM_RBUTTONUP=0x0205
WM_RBUTTONDBLCLK=0x0206
WM_MBUTTONDOWN=0x0207
WM_MBUTTONUP=0x0208
WM_MBUTTONDBLCLK=0x0209
WM_SETTEXT= 0x000C
WM_GETTEXT= 0x000D
WM_GETTEXTLENGTH= 0x000E
MK_LBUTTON=0x01
MK_RBUTTON=0x02
MK_SHIFT=0x04
MK_CONTROL=0x08
MK_MBUTTON=0x10
VK_LBUTTON=0x01
VK_RBUTTON=0x02
VK_CANCEL=0x03
VK_MBUTTON=0x04
VK_BACK=0x08
VK_TAB=0x09
VK_CLEAR=0x0C
VK_RETURN=0x0D
VK_SHIFT=0x10
VK_CONTROL=0x11
VK_MENU=0x12
VK_PAUSE=0x13
VK_CAPITAL=0x14
VK_KANA=0x15
VK_HANGEUL=
VK_HANGUL=
VL_JUNJA=0x17
VK_FINAL=0x18
VK_HANJA=0x19
VK_KANJI=
VK_ESCAPE=0x1B
VK_CONVERT=0x1C
VK_NONCONVERT=0x1D
VK_ACCEPT=0x1E
VK_MODECHANGE=0x1F
VK_SPACE=0x20
VK_PRIOR=0x21
VK_NEXT=0x22
VK_END=0x23
VK_HOME=0x24
VK_LEFT=0x25
VK_UP=0x26
VK_RIGHT=0x27
VK_DOWN=0x28
VK_SELECT=0x29
VK_PRINT=0x2A
VK_EXECUTE=0x2B
VK_SNAPSHOT=0x2C
VK_INSERT=0x2D
VK_DELETE=0x2E
VK_HELP=0x2F
VK_LWIN=0x5B
VK_RWIN=0x5C
VK_APpS=0x5D
VK_NUMPAD0=0x60
VK_NUMPAD1=0x61
VK_NUMPAD2=0x62
VK_NUMPAD3=0x63
VK_NUMPAD4=0x64
VK_NUMPAD5=0x65
VK_NUMPAD6=0x66
VK_NUMPAD7=0x67
VK_NUMPAD8=0x68
VK_NUMPAD9=0x69
VK_MULTIPLY=0x6A
VK_ADD=0x6B
VK_SEPARATOR=0x6C
VK_SUBTRACT=0x6D
VK_DECIMAL=0x6E
VK_DIVIDE=0x6F
VK_F1=0x70
VK_F2=0x71
VK_F3=0x72
VK_F4=0x73
VK_F5=0x74
VK_F6=0x75
VK_F7=0x76
VK_F8=0x77
VK_F9=0x78
VK_F10=0x79
VK_F11=0x7A
VK_F12=0x7B
VK_F13=0x7C
VK_F14=0x7D
VK_F15=0x7E
VK_F16=0x7F
VK_F17=0x80
VK_F18=0x81
VK_F19=0x82
VK_F20=0x83
VK_F21=0x84
VK_F22=0x85
VK_F23=0x86
VK_F24=0x87
VK_NUMLOCK=0x90
VK_SCROLL=0x91
VK_LSHIFT=0xA0
VK_RSHIFT=0xA1
VK_LCONTROL=0xA2
VK_RCONTROL=0xA3
VK_LMENU=0xA4
VK_RMENU=0xA5
VK_PROCESSKEY=0xE5
VK_ATTN=0xF6
VK_CRSEL=0xF7
VK_EXSEL=0xF8
VK_EREOF=0xF9
VK_PLAY=0xFA
VK_ZOOM=0xFB
VK_NONAME=0xFC
VK_PA1=0xFD
VK_OME_CLEAR=0xFE
# for Office(PowerPoint)
# VBA
MsoTrue =-1
MsoFalse=0
# Shapes
MsoShapeRectangle=1
MsoShapeParallelogram=2
MsoShapeTrapezoiod=3
MsoShapeDiamond=4
MsoShapeRoundRectangle=5
MsoShapeOctagon=6
MsoShapeIsoscelesTriangle=7
MsoShapeRightTriangle=8
MsoShapeOval=9
MsoShapeHexagon=10
MsoShapeCross=11
MsoShapeRegulaePentagon=12
MsoShapeCan=13
MsoShapeCube=14
MsoShapeBevel=15
MsoShapeFolderCorner=16
MsoShapeSmileyFace=17
MsoShapeDonut=18
MsoShapeNoSymbol=19
MsoShapeBlocArc=20
MsoShapeHeart=21
MsoShapeLightningBolt=22
MsoShapeSun=23
MsoShapeMoon=24
MsoShapeArc=25
MsoShapeDoubleBracket=26
MsoShapeDoubleBrace=27
MsoShapePlaque=28
MsoShapeLeftBracket=29
MsoShapeRightBlacket=30
MsoShapeLeftBrace=31
MsoShapeRightBrace=32
MsoShapeRightArrow=33
MsoShapeLeftArrow=34
MsoShapeUpArrow=35
MsoShapeDownArrow=36
MsoShapeLeftRightArrow=37
MsoShapeUpDownArrow=38
MsoShapeQuadArrow=39
MsoShapeLeftRightUpArrow=40
MsoShapeBentArrow=41
MsoShapeUTurnArrow=42
MsoShapeLeftUpArrow=43
MsoShapeBntUpArrow=44
MsoShapeCurvedRightArrow=45
MsoShapeCurvedLeftArrow=46
MsoShapeCurvedUpArrow=47
MsoShapeCurvedDownArrow=48
MsoShapeStripedRightArrow=49
MsoShapeNotchedRightArrow=50
MsoShapePentagon=51
MsoShapeChevron=52
MsoShapeRightArrowCallout=53
MsoShapeLeftArrowCallout=54
MsoShapeUpArrowCallout=55
MsoShapeDownArrowCallout=56
MsoShapeLeftRightArrowCallout=57
MsoShapeUpDownArrowCallout=58
MsoShapeQuadArrowCallout=59
MsoShapeCircularCallout=60
MsoShapeFlowChartProcess=61
MsoShapeFlowChartAlternateProcess=62
MsoShapeFlowChartDecision=63
MsoShapeFlowChartData=64
MsoShapeFlowChartPredefinedProcess=65
MsoShapeFlowChartInternalStorage=66
MsoShapeFlowChartDocument=67
MsoShapeFlowChartMultidocument=68
MsoShapeFlowChartTerminator=69
MsoShapeFlowChartPreparation=70
MsoShapeFlowChartManualInput=71
MsoShapeFlowChartManualOperation=72
MsoShapeFlowChartConnector=73
MsoShapeFlowChartOffpageConnector=74
MsoShapeFlowChartCard=75
MsoShapeFlowChartPunchedTape=76
MsoShapeFlowChartSummingJunction=77
MsoShapeFlowChartOr=78
MsoShapeFlowChartCollate=79
MsoShapeFlowChartSort=80
MsoShapeFlowChartExtract=81
MsoShapeFlowChartMerge=82
MsoShapeFlowChartStoredData=83
MsoShapeFlowChartDelay=84
MsoShapeFlowChartSquentialAccessStorage=85
MsoShapeFlowChartMagneticDisk=86
MsoShapeFlowChartDirectAccessStorage=87
MsoShapeFlowChartDisplay=88
MsoShapeExplosion1=89
MsoShapeExplosion2=90
MsoShape4pointStar=91
MsoShape5pointStar=92
MsoShape8pointStar=93
MsoShape16pointStar=94
MsoShape24pointStar=95
MsoShape32pointStar=96
MsoShapeUpRibbon=97
MsoShapeDownRibbon=98
MsoShapeCurvedUpRibbon=99
MsoShapeCurvedDownRibbon=100
MsoShapeVerticalScroll=101
MsoShapeHorizontalScroll=102
MsoShapeWave=103
MsoShapeDoubleWave=104
MsoShapeRectangularCallout=105
MsoShapeRoundedRectangularCallout=106
MsoShapeOvalCallout=107
MsoShapeCloudCallout=108
MsoShapeLineCallout1=109
MsoShapeLineCallout2=110
MsoShapeLineCallout3=111
MsoShapeLineCallout4=112
MsoShapeLineCallout1AccentBar=113
MsoShapeLineCallout2AccentBar=114
MsoShapeLineCallout3AccentBar=115
MsoShapeLineCallout4AccentBar=116
MsoShapeLineCallout1NoBorder=117
MsoShapeLineCallout2NoBorder=118
MsoShapeLineCallout3NoBorder=119
MsoShapeLineCallout4NoBorder=120
MsoShapeLineCallout1BorderandAccentBar=121
MsoShapeLineCallout2BorderandAccentBar=122
MsoShapeLineCallout3BorderandAccentBar=123
MsoShapeLineCallout4BorderandAccentBar=124
MsoShapeActionButtonCustom=125
MsoShapeActionButtonHome=126
MsoShapeActionButtonHelp=127
MsoShapeActionButtonInformation=128
MsoShapeActionButtonPrevious=129
MsoShapeActionButtonForwardNext=130
MsoShapeActionButtonBeggining=131
MsoShapeActionButtonEnd=132
MsoShapeActionButtonReturn=133
MsoShapeActionButtonDocument=134
MsoShapeActionButtonSound=135
MsoShapeActionButtonMovie=136
MsoShapeBaloon=137
MsoBringForward=2
MsoBringInFrontOfText= 4
MsoBringToFront = 0
MsoSendBackward = 3
MsoSendBehindText = 5
MsoSendToBack = 1
MsoAnimAccumulateAlways = 2
MsoAnimAccumulateNone = 1
MsoAnimAdditiveAddBase = 1
MsoAnimAdditiveAddSum = 2
MsoAnimAfterEffectDim = 1
MsoAnimAfterEffectHide = 2
MsoAnimAfterEffectHideOnNextClick = 3
MsoAnimAfterEffectMixed = -1
MsoAnimAfterEffectNone = 0
MsoAnimColor = 7
MsoAnimCommandTypeCall = 1
MsoAnimCommandTypeEvent = 0
MsoAnimCommandTypeVerb = 2
MsoAnimDirectionAcross = 18
MsoAnimDirectionBottom = 11
MsoAnimDirectionBottomLeft = 15
MsoAnimDirectionBottomRight = 14
MsoAnimDirectionCenter = 28
MsoAnimDirectionClockwise = 21
MsoAnimDirectionCycleClockwise = 43
MsoAnimDirectionCounterclockwise = 22
MsoAnimDirectionCycleCounterclockwise = 44
MsoAnimDirectionDown = 3
MsoAnimDirectionDownLeft = 9
MsoAnimDirectionDownRight = 8
MsoAnimDirectionFontAllCaps = 40
MsoAnimDirectionFontBold = 35
MsoAnimDirectionFontItalic = 36
MsoAnimDirectionFontShadow = 39
MsoAnimDirectionFontStrikethrough = 38
MsoAnimDirectionFontUnderline = 37
MsoAnimDirectionGradual = 42
MsoAnimDirectionHorizontal = 16
MsoAnimDirectionHorizontalIn = 23
MsoAnimDirectionHorizontalOut = 24
MsoAnimDirectionIn = 19
MsoAnimDirectionInBottom = 31
MsoAnimDirectionInCenter = 30
MsoAnimDirectionInSlightly = 29
MsoAnimDirectionInstant = 41
MsoAnimDirectionLeft = 4
MsoAnimDirectionNone = 0
MsoAnimDirectionOrdinalMask = 5
MsoAnimDirectionOut = 20
MsoAnimDirectionOutBottom = 34
MsoAnimDirectionOutCenter = 33
MsoAnimDirectionOutSlightly = 32
MsoAnimDirectionRight = 2
MsoAnimDirectionSlightly = 27
MsoAnimDirectionTop = 10
MsoAnimDirectionTopLeft = 12
MsoAnimDirectionTopRight = 13
MsoAnimDirectionUp = 1
MsoAnimDirectionUpLeft = 6
MsoAnimDirectionUpRight = 7
MsoAnimDirectionVertical = 17
MsoAnimDirectionVerticalIn = 25
MsoAnimDirectionVerticalOut = 26
MsoAnimEffectAfterFreeze = 1
MsoAnimEffectAfterHold = 3
MsoAnimEffectAfterRemove = 2
MsoAnimEffectAfterTransition = 4
MsoAnimEffectAPpear = 1
MsoAnimEffectArcUp = 47
MsoAnimEffectAscend = 39
MsoAnimEffectBlast = 64
MsoAnimEffectBlinds = 3
MsoAnimEffectBoldFlash = 63
MsoAnimEffectBoldReveal = 65
MsoAnimEffectBoomerang = 25
MsoAnimEffectBounce = 26
MsoAnimEffectBox = 4
MsoAnimEffectBrushOnColor = 66
MsoAnimEffectBrushOnUnderline = 67
MsoAnimEffectCenterRevolve = 40
MsoAnimEffectChangeFillColor = 54
MsoAnimEffectChangeFont = 55
MsoAnimEffectChangeFontColor = 56
MsoAnimEffectChangeFontSize = 57
MsoAnimEffectChangeFontStyle = 58
MsoAnimEffectChangeLineColor = 60
MsoAnimEffectCheckerboard = 5
MsoAnimEffectCircle = 6
MsoAnimEffectColorBlend = 68
MsoAnimEffectColorReveal = 27
MsoAnimEffectColorWave = 69
MsoAnimEffectComplementaryColor = 70
MsoAnimEffectComplementaryColor2 = 71
MsoAnimEffectContrastingColor = 72
MsoAnimEffectCrawl = 7
MsoAnimEffectCredits = 28
MsoAnimEffectCustom = 0
MsoAnimEffectDarken = 73
MsoAnimEffectDesaturate = 74
MsoAnimEffectDescend = 42
MsoAnimEffectDiamond = 8
MsoAnimEffectDissolve = 9
MsoAnimEffectEaseIn = 29
MsoAnimEffectExpand = 50
MsoAnimEffectFade = 10
MsoAnimEffectFadedSwivel = 41
MsoAnimEffectFadedZoom = 48
MsoAnimEffectFlashBulb = 75
MsoAnimEffectFlashOnce = 11
MsoAnimEffectFlicker = 76
MsoAnimEffectFlip = 51
MsoAnimEffectFloat = 30
MsoAnimEffectFly = 2
MsoAnimEffectFold = 53
MsoAnimEffectGlide = 49
MsoAnimEffectGrowAndTurn = 31
MsoAnimEffectGrowShrink = 59
MsoAnimEffectGrowWithColor = 77
MsoAnimEffectLightSpeed = 32
MsoAnimEffectLighten = 78
MsoAnimEffectMediaPause = 84
MsoAnimEffectMediaPlay = 83
MsoAnimEffectMediaStop = 85
MsoAnimEffectPath4PointStar = 101
MsoAnimEffectPath5PointStar = 90
MsoAnimEffectPath6PointStar = 96
MsoAnimEffectPath8PointStar = 102
MsoAnimEffectPathArcDown = 122
MsoAnimEffectPathArcLeft = 136
MsoAnimEffectPathArcRight = 143
MsoAnimEffectPathArcUp = 129
MsoAnimEffectPathBean = 116
MsoAnimEffectPathBounceLeft = 126
MsoAnimEffectPathBounceRight = 139
MsoAnimEffectPathBuzzsaw = 110
MsoAnimEffectPathCircle = 86
MsoAnimEffectPathCrescentMoon = 91
MsoAnimEffectPathCurvedSquare = 105
MsoAnimEffectPathCurvedX = 106
MsoAnimEffectPathCurvyLeft = 133
MsoAnimEffectPathCurvyRight = 146
MsoAnimEffectPathCurvyStar = 108
MsoAnimEffectPathDecayingWave = 145
MsoAnimEffectPathDiagonalDownRight = 134
MsoAnimEffectPathDiagonalUpRight = 141
MsoAnimEffectPathDiamond = 88
MsoAnimEffectPathDown = 127
MsoAnimEffectPathEqualTriangle = 98
MsoAnimEffectPathFigure8Four = 113
MsoAnimEffectPathFootball = 97
MsoAnimEffectPathFunnel = 137
MsoAnimEffectPathHeart = 94
MsoAnimEffectPathHeartbeat = 130
MsoAnimEffectPathHexagon = 89
MsoAnimEffectPathHorizontalFigure8 = 111
MsoAnimEffectPathInvertedSquare = 119
MsoAnimEffectPathInvertedTriangle = 118
MsoAnimEffectPathLeft = 120
MsoAnimEffectPathLoopdeLoop = 109
MsoAnimEffectPathNeutron = 114
MsoAnimEffectPathOctagon = 95
MsoAnimEffectPathParallelogram = 99
MsoAnimEffectPathPeanut = 112
MsoAnimEffectPathPentagon = 100
MsoAnimEffectPathPlus = 117
MsoAnimEffectPathPointyStar = 104
MsoAnimEffectPathRight = 149
MsoAnimEffectPathRightTriangle = 87
MsoAnimEffectPathSCurve1 = 144
MsoAnimEffectPathSCurve2 = 124
MsoAnimEffectPathSineWave = 125
MsoAnimEffectPathSpiralLeft = 140
MsoAnimEffectPathSpiralRight = 131
MsoAnimEffectPathSpring = 138
MsoAnimEffectPathSquare = 92
MsoAnimEffectPathStairsDown = 147
MsoAnimEffectPathSwoosh = 115
MsoAnimEffectPathTeardrop = 103
MsoAnimEffectPathTrapezoid = 93
MsoAnimEffectPathTurnDown = 135
MsoAnimEffectPathTurnRight = 121
MsoAnimEffectPathTurnUp = 128
MsoAnimEffectPathTurnUpRight = 142
MsoAnimEffectPathUp = 148
MsoAnimEffectPathVerticalFigure8 = 107
MsoAnimEffectPathWave = 132
MsoAnimEffectPathZigzag = 123
MsoAnimEffectPeek = 12
MsoAnimEffectPinwheel = 33
MsoAnimEffectPlus = 13
MsoAnimEffectRandomBars = 14
MsoAnimEffectRandomEffects = 24
MsoAnimEffectRestartAlways = 1
MsoAnimEffectRestartNever = 3
MsoAnimEffectRestartWhenOff = 2
MsoAnimEffectRiseUp = 34
MsoAnimEffectShimmer = 52
MsoAnimEffectSling = 43
MsoAnimEffectSpin = 61
MsoAnimEffectSpinner = 44
MsoAnimEffectSpiral = 15
MsoAnimEffectSplit = 16
MsoAnimEffectStretch = 17
MsoAnimEffectStretchy = 45
MsoAnimEffectStrips = 18
MsoAnimEffectStyleEmphasis = 79
MsoAnimEffectSwish = 35
MsoAnimEffectSwivel = 19
MsoAnimEffectTeeter = 80
MsoAnimEffectThinLine = 36
MsoAnimEffectTransparency = 62
MsoAnimEffectUnfold = 37
MsoAnimEffectVerticalGrow = 81
MsoAnimEffectWave = 82
MsoAnimEffectWedge = 20
MsoAnimEffectWheel = 21
MsoAnimEffectWhip = 38
MsoAnimEffectWipe = 22
MsoAnimEffectZip = 46
MsoAnimEffectZoom = 23
MsoAnimFilterEffectSubtypeAcross = 9
MsoAnimFilterEffectSubtypeDown = 25
MsoAnimFilterEffectSubtypeDownLeft = 14
MsoAnimFilterEffectSubtypeDownRight = 16
MsoAnimFilterEffectSubtypeFromBottom = 13
MsoAnimFilterEffectSubtypeFromLeft = 10
MsoAnimFilterEffectSubtypeFromRight = 11
MsoAnimFilterEffectSubtypeFromTop = 12
MsoAnimFilterEffectSubtypeHorizontal = 5
MsoAnimFilterEffectSubtypeIn = 7
MsoAnimFilterEffectSubtypeInHorizontal = 3
MsoAnimFilterEffectSubtypeInVertical = 1
MsoAnimFilterEffectSubtypeLeft = 23
MsoAnimFilterEffectSubtypeNone = 0
MsoAnimFilterEffectSubtypeOut = 8
MsoAnimFilterEffectSubtypeOutHorizontal = 4
MsoAnimFilterEffectSubtypeOutVertical = 2
MsoAnimFilterEffectSubtypeRight = 24
MsoAnimFilterEffectSubtypeSpokes1 = 18
MsoAnimFilterEffectSubtypeSpokes2 = 19
MsoAnimFilterEffectSubtypeSpokes3 = 20
MsoAnimFilterEffectSubtypeSpokes4 = 21
MsoAnimFilterEffectSubtypeSpokes8 = 22
MsoAnimFilterEffectSubtypeUp = 26
MsoAnimFilterEffectSubtypeUpLeft = 15
MsoAnimFilterEffectSubtypeUpRight = 17
MsoAnimFilterEffectSubtypeVertical = 6
MsoAnimFilterEffectTypeBarn = 1
MsoAnimFilterEffectTypeBlinds = 2
MsoAnimFilterEffectTypeBox = 3
MsoAnimFilterEffectTypeCheckerboard = 4
MsoAnimFilterEffectTypeCircle = 5
MsoAnimFilterEffectTypeDiamond = 6
MsoAnimFilterEffectTypeDissolve = 7
MsoAnimFilterEffectTypeFade = 8
MsoAnimFilterEffectTypeImage = 9
MsoAnimFilterEffectTypeNone = 0
MsoAnimFilterEffectTypePixelate = 10
MsoAnimFilterEffectTypePlus = 11
MsoAnimFilterEffectTypeRandomBar = 12
MsoAnimFilterEffectTypeSlide = 13
MsoAnimFilterEffectTypeStretch = 14
MsoAnimFilterEffectTypeStrips = 15
MsoAnimFilterEffectTypeWedge = 16
MsoAnimFilterEffectTypeWheel = 17
MsoAnimFilterEffectTypeWipe = 18
MsoAnimHeight = 4
MsoAnimNone = 0
MsoAnimOpacity = 5
MsoAnimRotation = 6
MsoAnimShapeFillBackColor = 1007
MsoAnimShapeFillColor = 1005
MsoAnimShapeFillOn = 1004
MsoAnimShapeFillOpacity = 1006
MsoAnimShapeLineColor = 1009
MsoAnimShapeLineOn = 1008
MsoAnimShapePictureBrightness = 1001
MsoAnimShapePictureContrast = 1000
MsoAnimShapePictureGamma = 1002
MsoAnimShapePictureGrayscale = 1003
MsoAnimShapeShadowColor = 1012
MsoAnimShapeShadowOffsetX = 1014
MsoAnimShapeShadowOffsetY = 1015
MsoAnimShapeShadowOn = 1010
MsoAnimShapeShadowOpacity = 1013
MsoAnimShapeShadowType = 1011
MsoAnimTextBulletCharacter = 111
MsoAnimTextBulletColor = 114
MsoAnimTextBulletFontName = 112
MsoAnimTextBulletNumber = 113
MsoAnimTextBulletRelativeSize = 115
MsoAnimTextBulletStyle = 116
MsoAnimTextBulletType = 117
MsoAnimTextFontBold = 100
MsoAnimTextFontColor = 101
MsoAnimTextFontEmboss = 102
MsoAnimTextFontItalic = 103
MsoAnimTextFontName = 104
MsoAnimTextFontShadow = 105
MsoAnimTextFontSize = 106
MsoAnimTextFontStrikeThrough = 110
MsoAnimTextFontSubscript = 107
MsoAnimTextFontSuperscript = 108
MsoAnimTextFontUnderline = 109
MsoAnimTextUnitEffectByCharacter = 1
MsoAnimTextUnitEffectByParagraph = 0
MsoAnimTextUnitEffectByWord = 2
MsoAnimTextUnitEffectMixed = -1
MsoAnimTriggerAfterPrevious = 3
MsoAnimTriggerMixed = -1
MsoAnimTriggerNone = 0
MsoAnimTriggerOnPageClick = 1
MsoAnimTriggerOnShapeClick = 4
MsoAnimTriggerWithPrevious = 2
MsoAnimTypeColor = 2
MsoAnimTypeCommand = 6
MsoAnimTypeFilter = 7
MsoAnimTypeMixed = -2
MsoAnimTypeMotion = 1
MsoAnimTypeNone = 0
MsoAnimTypeProperty = 5
MsoAnimTypeRotation = 4
MsoAnimTypeScale = 3
MsoAnimTypeSet = 8
MsoAnimVisibility = 8
MsoAnimWidth = 3
MsoAnimX = 1
MsoAnimY = 2
MsoAnimateChartAllAtOnce = 7
MsoAnimateChartByCategory = 8
MsoAnimateChartByCategoryElements = 9
MsoAnimateChartBySeries = 10
MsoAnimateChartBySeriesElements = 11
MsoAnimateDiagramAllAtOnce = 12
MsoAnimateDiagramBreadthByLevel = 16
MsoAnimateDiagramBreadthByNode = 15
MsoAnimateDiagramClockwise = 17
MsoAnimateDiagramClockwiseIn = 18
MsoAnimateDiagramClockwiseOut = 19
MsoAnimateDiagramCounterClockwise = 20
MsoAnimateDiagramCounterClockwiseIn = 21
MsoAnimateDiagramCounterClockwiseOut = 22
MsoAnimateDiagramDepthByBranch = 14
MsoAnimateDiagramDepthByNode = 13
MsoAnimateDiagramDown = 26
MsoAnimateDiagramInByRing = 23
MsoAnimateDiagramOutByRing = 24
MsoAnimateDiagramUp = 25
MsoAnimateLevelMixed = -1
MsoAnimateLevelNone = 0
MsoAnimateTextByAllLevels = 1
MsoAnimateTextByFifthLevel = 6
MsoAnimateTextByFirstLevel = 2
MsoAnimateTextByFourthLevel = 5
MsoAnimateTextBySecondLevel = 3
MsoAnimateTextByThirdLevel = 4
MsoClickStateAfterAllAnimations = -2
MsoClickStateBeforeAutomaticAnimations = -1
# for PowerPoint
PpAccent1 = 6
PpAccent2 = 7
PpAccent3 = 8
PpActionEndShow = 6
PpActionFirstSlide = 3
PpActionHyperlink = 7
PpActionLastSlide = 4
PpActionLastSlideViewed = 5
PpActionMixed = -2
PpActionNamedSlideShow = 10
PpActionNextSlide = 1
PpActionNone = 0
PpActionOLEVerb = 11
PpActionPlay = 12
PpActionPreviousSlide = 2
PpActionRunMacro = 8
PpActionRunProgram = 9
PpAdvanceModeMixed = -2
PpAdvanceOnClick = 1
PpAdvanceOnTime = 2
PpAfterEffectDim = 2
PpAfterEffectHide = 1
PpAfterEffectHideOnClick = 3
PpAfterEffectMixed = -2
PpAfterEffectNothing = 0
PpAlertsAll = 2
PpAlertsNone = 1
PpAlignCenter = 2
PpAlignDistribute = 5
PpAlignJustify = 4
PpAlignJustifyLow = 7
PpAlignLeft = 1
PpAlignRight = 3
PpAlignThaiDistribute = 6
PpAlignmentMixed = -2
PpAnimateByAllLevels = 16
PpAnimateByCategory = 2
PpAnimateByCategoryElements = 4
PpAnimateByCharacter = 2
PpAnimateByFifthLevel = 5
PpAnimateByFirstLevel = 1
PpAnimateByFourthLevel = 4
PpAnimateByParagraph = 0
PpAnimateBySecondLevel = 2
PpAnimateBySeries = 1
PpAnimateBySeriesElements = 3
PpAnimateByThirdLevel = 3
PpAnimateByWord = 1
PpAnimateChartAllAtOnce = 5
PpAnimateChartMixed = -2
PpAnimateLevelMixed = -2
PpAnimateLevelNone = 0
PpAnimateUnitMixed = -2
PpArrangeCascade = 2
PpArrangeTiled = 1
PpAutoSizeMixed = -2
PpAutoSizeNone = 0
PpAutoSizeShapeToFitText = 1
PpBackground = 1
PpBaselineAlignAuto = 5
PpBaselineAlignBaseline = 1
PpBaselineAlignCenter = 3
PpBaselineAlignFarEast50 = 4
PpBaselineAlignMixed = -2
PpBaselineAlignTop = 2
PpBodyStyle = 3
PpBorderBottom = 3
PpBorderDiagonalDown = 5
PpBorderDiagonalUp = 6
PpBorderLeft = 2
PpBorderRight = 4
PpBorderTop = 1
PpBulletAlphaLCParenBoth = 8
PpBulletAlphaLCParenRight = 9
PpBulletAlphaLCPeriod = 0
PpBulletAlphaUCParenBoth = 10
PpBulletAlphaUCParenRight = 11
PpBulletAlphaUCPeriod = 1
PpBulletArabicAbjadDash = 24
PpBulletArabicAlphaDash = 23
PpBulletArabicDBPeriod = 29
PpBulletArabicDBPlain = 28
PpBulletArabicParenBoth = 12
PpBulletArabicParenRight = 2
PpBulletArabicPeriod = 3
PpBulletArabicPlain = 13
PpBulletCircleNumDBPlain = 18
PpBulletCircleNumWDBlackPlain = 20
PpBulletCircleNumWDWhitePlain = 19
PpBulletHebrewAlphaDash = 25
PpBulletHindiAlpha1Period = 40
PpBulletHindiAlphaPeriod = 36
PpBulletHindiNumParenRight = 39
PpBulletHindiNumPeriod = 37
PpBulletKanjiKoreanPeriod = 27
PpBulletKanjiKoreanPlain = 26
PpBulletKanjiSimpChinDBPeriod = 38
PpBulletMixed = -2
PpBulletNone = 0
PpBulletNumbered = 2
PpBulletPicture = 3
PpBulletRomanLCParenBoth = 4
PpBulletRomanLCParenRight = 5
PpBulletRomanLCPeriod = 6
PpBulletRomanUCParenBoth = 14
PpBulletRomanUCParenRight = 15
PpBulletRomanUCPeriod = 7
PpBulletSimpChinPeriod = 17
PpBulletSimpChinPlain = 16
PpBulletStyleMixed = -2
PpBulletThaiAlphaParenBoth = 32
PpBulletThaiAlphaParenRight = 31
PpBulletThaiAlphaPeriod = 30
PpBulletThaiNumParenBoth = 35
PpBulletThaiNumParenRight = 34
PpBulletThaiNumPeriod = 33
PpBulletTradChinPeriod = 22
PpBulletTradChinPlain = 21
PpBulletUnnumbered = 1
PpCaseLower = 2
PpCaseSentence = 1
PpCaseTitle = 4
PpCaseToggle = 5
PpCaseUPper = 3
PpCheckInMajorVersion = 1
PpCheckInMinorVersion = 0
PpCheckInOverwriteVersion = 2
PpDateTimeFigureOut = 14
PpDateTimeFormatMixed = -2
PpDateTimeHmm = 10
PpDateTimeHmmss = 11
PpDateTimeMMMMdyyyy = 4
PpDateTimeMMMMyy = 6
PpDateTimeMMddyyHmm = 8
PpDateTimeMMddyyhmmAMPM = 9
PpDateTimeMMyy = 7
PpDateTimeMdyy = 1
PpDateTimedMMMMyyyy = 3
PpDateTimedMMMyy = 5
PpDateTimeddddMMMMddyyyy = 2
PpDateTimehmmAMPM = 12
PpDateTimehmmssAMPM = 13
PpDefaultStyle = 1
PpDirectionLeftToRight = 1
PpDirectionMixed = -2
PpDirectionRightToLeft = 2
PpEffectAPpear = 3844
PpEffectBlindsHorizontal = 769
PpEffectBlindsVertical = 770
PpEffectBoxIn = 3074
PpEffectBoxOut = 3073
PpEffectCheckerboardAcross = 1025
PpEffectCheckerboardDown = 1026
PpEffectCircleOut = 3845
PpEffectCombHorizontal = 3847
PpEffectCombVertical = 3848
PpEffectCoverDown = 1284
PpEffectCoverLeft = 1281
PpEffectCoverLeftDown = 1287
PpEffectCoverLeftUp = 1285
PpEffectCoverRight = 1283
PpEffectCoverRightDown = 1288
PpEffectCoverRightUp = 1286
PpEffectCoverUp = 1282
PpEffectCrawlFromDown = 3344
PpEffectCrawlFromLeft = 3341
PpEffectCrawlFromRight = 3343
PpEffectCrawlFromUp = 3342
PpEffectCut = 257
PpEffectCutThroughBlack = 258
PpEffectDiamondOut = 3846
PpEffectDissolve = 1537
PpEffectFade = 1793
PpEffectFadeSmoothly = 3849
PpEffectFlashOnceFast = 3841
PpEffectFlashOnceMedium = 3842
PpEffectFlashOnceSlow = 3843
PpEffectFlyFromBottom = 3332
PpEffectFlyFromBottomLeft = 3335
PpEffectFlyFromBottomRight = 3336
PpEffectFlyFromLeft = 3329
PpEffectFlyFromRight = 3331
PpEffectFlyFromTop = 3330
PpEffectFlyFromTopLeft = 3333
PpEffectFlyFromTopRight = 3334
PpEffectMixed = -2
PpEffectNewsflash = 3850
PpEffectNone = 0
PpEffectPeekFromDown = 3338
PpEffectPeekFromLeft = 3337
PpEffectPeekFromRight = 3339
PpEffectPeekFromUp = 3340
PpEffectPlusOut = 3851
PpEffectPushDown = 3852
PpEffectPushLeft = 3853
PpEffectPushRight = 3854
PpEffectPushUp = 3855
PpEffectRandom = 513
PpEffectRandomBarsHorizontal = 2305
PpEffectRandomBarsVertical = 2306
PpEffectSpiral = 3357
PpEffectSplitHorizontalIn = 3586
PpEffectSplitHorizontalOut = 3585
PpEffectSplitVerticalIn = 3588
PpEffectSplitVerticalOut = 3587
PpEffectStretchAcross = 3351
PpEffectStretchDown = 3355
PpEffectStretchLeft = 3352
PpEffectStretchRight = 3354
PpEffectStretchUp = 3353
PpEffectStripsDownLeft = 2563
PpEffectStripsDownRight = 2564
PpEffectStripsLeftDown = 2567
PpEffectStripsLeftUp = 2565
PpEffectStripsRightDown = 2568
PpEffectStripsRightUp = 2566
PpEffectStripsUpLeft = 2561
PpEffectStripsUpRight = 2562
PpEffectSwivel = 3356
PpEffectUncoverDown = 2052
PpEffectUncoverLeft = 2049
PpEffectUncoverLeftDown = 2055
PpEffectUncoverLeftUp = 2053
PpEffectUncoverRight = 2051
PpEffectUncoverRightDown = 2056
PpEffectUncoverRightUp = 2054
PpEffectUncoverUp = 2050
PpEffectWedge = 3856
PpEffectWheel1Spoke = 3857
PpEffectWheel2Spokes = 3858
PpEffectWheel3Spokes = 3859
PpEffectWheel4Spokes = 3860
PpEffectWheel8Spokes = 3861
PpEffectWipeDown = 2820
PpEffectWipeLeft = 2817
PpEffectWipeRight = 2819
PpEffectWipeUp = 2818
PpEffectZoomBottom = 3350
PpEffectZoomCenter = 3349
PpEffectZoomIn = 3345
PpEffectZoomInSlightly = 3346
PpEffectZoomOut = 3347
PpEffectZoomOutSlightly = 3348
PpFarEastLineBreakLevelCustom = 3
PpFarEastLineBreakLevelNormal = 1
PpFarEastLineBreakLevelStrict = 2
PpFill = 5
PpFixedFormatIntentPrint = 2
PpFixedFormatIntentScreen = 1
PpFixedFormatTypePDF = 2
PpFixedFormatTypeXPS = 1
PpFollowColorsMixed = -2
PpFollowColorsNone = 0
PpFollowColorsScheme = 1
PpFollowColorsTextAndBackground = 2
PpForeground = 2
PpFrameColorsBlackTextOnWhite = 5
PpFrameColorsBrowserColors = 1
PpFrameColorsPresentationSchemeAccentColor = 3
PpFrameColorsPresentationSchemeTextColor = 2
PpFrameColorsWhiteTextOnBlack = 4
PpHTMLAutodetect = 4
PpHTMLDual = 3
PpHTMLv3 = 1
PpHTMLv4 = 2
PpIndentControlMixed = -2
PpIndentKeepAttr = 2
PpIndentReplaceAttr = 1
PpLayoutBlank = 12
PpLayoutChart = 8
PpLayoutChartAndText = 6
PpLayoutClipArtAndVerticalText = 26
PpLayoutClipartAndText = 10
PpLayoutComparison = 34
PpLayoutContentWithCaption = 35
PpLayoutCustom = 32
PpLayoutFourObjects = 24
PpLayoutLargeObject = 15
PpLayoutMediaClipAndText = 18
PpLayoutMixed = -2
PpLayoutObject = 16
PpLayoutObjectAndText = 14
PpLayoutObjectAndTwoObjects = 30
PpLayoutObjectOverText = 19
PpLayoutOrgchart = 7
PpLayoutPictureWithCaption = 36
PpLayoutSectionHeader = 33
PpLayoutTable = 4
PpLayoutText = 2
PpLayoutTextAndChart = 5
PpLayoutTextAndClipart = 9
PpLayoutTextAndMediaClip = 17
PpLayoutTextAndObject = 13
PpLayoutTextAndTwoObjects = 21
PpLayoutTextOverObject = 20
PpLayoutTitle = 1
PpLayoutTitleOnly = 11
PpLayoutTwoColumnText = 3
PpLayoutTwoObjects = 29
PpLayoutTwoObjectsAndObject = 31
PpLayoutTwoObjectsAndText = 22
PpLayoutTwoObjectsOverText = 23
PpLayoutVerticalText = 25
PpLayoutVerticalTitleAndText = 27
PpLayoutVerticalTitleAndTextOverChart = 28
PpMediaTypeMixed = -2
PpMediaTypeMovie = 3
PpMediaTypeOther = 1
PpMediaTypeSound = 2
PpMouseClick = 1
PpMouseOver = 2
PpNotSchemeColor = 0
PpPasteBitmap = 1
PpPasteDefault = 0
PpPasteEnhancedMetafile = 2
PpPasteGIF = 4
PpPasteHTML = 8
PpPasteJPG = 5
PpPasteMetafilePicture = 3
PpPasteOLEObject = 10
PpPastePNG = 6
PpPasteRTF = 9
PpPasteShape = 11
PpPasteText = 7
PpPlaceholderBitmap = 9
PpPlaceholderBody = 2
PpPlaceholderCenterTitle = 3
PpPlaceholderChart = 8
PpPlaceholderDate = 16
PpPlaceholderFooter = 15
PpPlaceholderHeader = 14
PpPlaceholderMediaClip = 10
PpPlaceholderMixed = -2
PpPlaceholderObject = 7
PpPlaceholderOrgChart = 11
PpPlaceholderPicture = 18
PpPlaceholderSlideNumber = 13
PpPlaceholderSubtitle = 4
PpPlaceholderTable = 12
PpPlaceholderTitle = 1
PpPlaceholderVerticalBody = 6
PpPlaceholderVerticalObject = 17
PpPlaceholderVerticalTitle = 5
PpPrintAll = 1
PpPrintBlackAndWhite = 2
PpPrintColor = 1
PpPrintCurrent = 3
PpPrintHandoutHorizontalFirst = 2
PpPrintHandoutVerticalFirst = 1
PpPrintNamedSlideShow = 5
PpPrintOutputBuildSlides = 7
PpPrintOutputFourSlideHandouts = 8
PpPrintOutputNineSlideHandouts = 9
PpPrintOutputNotesPages = 5
PpPrintOutputOneSlideHandouts = 10
PpPrintOutputOutline = 6
PpPrintOutputSixSlideHandouts = 4
PpPrintOutputSlides = 1
PpPrintOutputThreeSlideHandouts = 3
PpPrintOutputTwoSlideHandouts = 2
PpPrintPureBlackAndWhite = 3
PpPrintSelection = 2
PpPrintSlideRange = 4
PpPublishAll = 1
PpPublishNamedSlideShow = 3
PpPublishSlideRange = 2
PpRDIAll = 99
PpRDIComments = 1
PpRDIContentType = 16
PpRDIDocumentManagementPolicy = 15
PpRDIDocumentProperties = 8
PpRDIDocumentServerProperties = 14
PpRDIDocumentWorkspace = 10
PpRDIInkAnnotations = 11
PpRDIPublishPath = 13
PpRDIRemovePersonalInformation = 4
PpRDISlideUpdateInformation = 17
PpRevisionInfoBaseline = 1
PpRevisionInfoMerged = 2
PpRevisionInfoNone = 0
PpSaveAsAddIn = 8
PpSaveAsBMP = 19
PpSaveAsDefault = 11
PpSaveAsEMF = 23
PpSaveAsGIF = 16
PpSaveAsHTML = 12
PpSaveAsHTMLDual = 14
PpSaveAsHTMLv3 = 13
PpSaveAsJPG = 17
PpSaveAsMetaFile = 15
PpSaveAsOpenXMLAddin = 30
PpSaveAsOpenXMLPresentation = 24
PpSaveAsOpenXMLPresentationMacroEnabled = 25
PpSaveAsOpenXMLShow = 28
PpSaveAsOpenXMLShowMacroEnabled = 29
PpSaveAsOpenXMLTemplate = 26
PpSaveAsOpenXMLTemplateMacroEnabled = 27
PpSaveAsOpenXMLTheme = 31
PpSaveAsPDF = 32
PpSaveAsPNG = 18
PpSaveAsPresentation = 1
PpSaveAsRTF = 6
PpSaveAsShow = 7
PpSaveAsTIF = 21
PpSaveAsTemplate = 5
PpSaveAsWebArchive = 20
PpSaveAsXMLPresentation = 34
PpSaveAsXPS = 33
PpSchemeColorMixed = -2
PpSelectionNone = 0
PpSelectionShapes = 2
PpSelectionSlides = 1
PpSelectionText = 3
PpShadow = 3
PpShowAll = 1
PpShowNamedSlideShow = 3
PpShowSlideRange = 2
PpShowTypeKiosk = 3
PpShowTypeSpeaker = 1
PpShowTypeWindow = 2
PpSlideShowBlackScreen = 3
PpSlideShowDone = 5
PpSlideShowManualAdvance = 1
PpSlideShowPaused = 2
PpSlideShowPointerAlwaysHidden = 3
PpSlideShowPointerArrow = 1
PpSlideShowPointerAutoArrow = 4
PpSlideShowPointerEraser = 5
PpSlideShowPointerNone = 0
PpSlideShowPointerPen = 2
PpSlideShowRehearseNewTimings = 3
PpSlideShowRunning = 1
PpSlideShowUseSlideTimings = 2
PpSlideShowWhiteScreen = 4
PpSlideSize35MM = 4
PpSlideSizeA3Paper = 9
PpSlideSizeA4Paper = 3
PpSlideSizeB4ISOPaper = 10
PpSlideSizeB4JISPaper = 12
PpSlideSizeB5ISOPaper = 11
PpSlideSizeB5JISPaper = 13
PpSlideSizeBanner = 6
PpSlideSizeCustom = 7
PpSlideSizeHagakiCard = 14
PpSlideSizeLedgerPaper = 8
PpSlideSizeLetterPaper = 2
PpSlideSizeOnScreen = 1
PpSlideSizeOnScreen16x10 = 16
PpSlideSizeOnScreen16x9 = 15
PpSlideSizeOverhead = 5
PpSoundEffectsMixed = -2
PpSoundFile = 2
PpSoundFormatCDAudio = 3
PpSoundFormatMIDI = 2
PpSoundFormatMixed = -2
PpSoundFormatNone = 0
PpSoundFormatWAV = 1
PpSoundNone = 0
PpSoundStoPprevious = 1
PpTabStopCenter = 2
PpTabStopDecimal = 4
PpTabStopLeft = 1
PpTabStopMixed = -2
PpTabStopRight = 3
PpTitle = 4
PpTitleStyle = 2
PpTransitionSpeedFast = 3
PpTransitionSpeedMedium = 2
PpTransitionSpeedMixed = -2
PpTransitionSpeedSlow = 1
PpUpdateOptionAutomatic = 2
PpUpdateOptionManual = 1
PpUpdateOptionMixed = -2
PpViewHandoutMaster = 4
PpViewMasterThumbnails = 12
PpViewNormal = 9
PpViewNotesMaster = 5
PpViewNotesPage = 3
PpViewOutline = 6
PpViewPrintPreview = 10
PpViewSlide = 1
PpViewSlideMaster = 2
PpViewSlideSorter = 7
PpViewThumbnails = 11
PpViewTitleMaster = 8
PpWindowMaximized = 3
PpWindowMinimized = 2
PpWindowNormal = 1
end
include Constants
def initialize
# WIN32OLE
@wsh=WIN32OLE.new("WScript.Shell")
# API
@getAsyncKeyStateAPI=Win32API.new("user32", "GetAsyncKeyState", ['i'], 'L')
@getKeyStateAPI=Win32API.new("user32", "GetKeyState", ['i'], 'L')
@getKeyboardStateAPI=Win32API.new("user32", "GetKeyboardState", ['P'], 'V')
@setCursorPosAPI=Win32API.new("user32", "SetCursorPos", ['i', 'i'], 'V')
@getCursorPosAPI=Win32API.new("user32", "GetCursorPos", ['P'], 'V')
@mouseEventAPI=Win32API.new("user32", "mouse_event",['l', 'l','l', 'l','l'],'V')
@findWindowExAPI= Win32API.new("user32", "FindWindowEx", ['L','L','P', 'P'], 'L')
@findWindowAPI=Win32API.new("user32", "FindWindow",['P', 'P'],'I')
@getTopWindowAPI=Win32API.new("user32", "GetTopWindow",['L'],'L')
@getWindowTextAPI=Win32API.new("user32", "GetWindowText",['l','P','l'],'I')
@setForegroundWindowAPI=Win32API.new("user32", "SetForegroundWindow",['l'],'V')
@getClassNameAPI=Win32API.new("user32", "GetClassName",['l','P','l'],'V')
@setFocusAPI=Win32API.new("user32", "SetFocus",['l'],'V')
@getForegroundWindowAPI=Win32API.new("user32", "GetForegroundWindow",[],'I')
@getWindowRectAPI=Win32API.new("user32", "GetWindowRect",['I','P'],'V')
@moveWindowAPI=Win32API.new("user32", "MoveWindow",['I','I','I','I','I','I'],'V')
@sendMessageAPI=Win32API.new("user32", "SendMessage",['L','L','L','L'],'V')
@postMessageAPI=Win32API.new("user32", "PostMessage",['L','L','L','L'],'V')
@playSoundAPI=Win32API.new('winmm','PlaySound','ppl','i')
@mciSendStringAPI=Win32API.new('winmm','mciSendString',['P'],'V')
# USER32
@user32=DL.dlopen("user32")
@enumWindows=@user32['EnumWindows', '0PL']
@enumChildWindows=@user32['EnumChildWindows', '0IPL']
end
def closeComandWindowLikeName(name,delay=2)
findWindowLikeName(name).first.each{|w|
setForegroundWindow(w)
sleep delay
sendKeys('% ',delay) # ALT+SPACE
sendKeys('c',delay)
}
end
def run(fileOrApl)
@wsh.Run(fileOrApl)
end
def sendKeys(keys, delay=0)
sleep delay
@wsh.SendKeys(keys)
# {BACKSPACE}{BS}{BKSP}
#{BREAK}
#{CAPSLOCK}
#{DELETE}{DEL}
#{DOWN}
#{END}
#{ENTER}
#{ESC}
#{HELP}
#{HOME}
#{INSERT}{INS}
#{LEFT}
#{NUMLOCK}
#{PGDN}
#{PGUP}
#{PRTSC}
#{RIGHT}
#{SCROLLLOCK}
#{TAB}
#{UP}
#{F1} ... {F12}
#Shit = +() ex "+(T)his is a sanple."
#Ctrl= ^()
#Alt= %()
#+ {+}
#^ {^}
#% {%}
#{ {{}
#} {}}
# {a 100} means type a 100 times
end
def sendMouse(command,x=0.2,y=0.2)
case command
when "LEFTDOWN"
sendLButtonDown
when "LEFTUP"
sendLButtonUp
when "MIDDLEDOWN"
sendMButtonDown
when "MIDDLEUP"
sendMButtonUp
when "RIGHTDOWN"
sendRButtonDown
when "RIGHTUP"
sendRButtonUp
when "LEFTCLICK"
sendLButtonDown
sleep x
sendLButtonUp
when "MIDDLECLICK"
sendMButtonDown
sleep x
sendMButtonUp
when "RIGHTCLICK"
sendRButtonDown
sleep x
sendRButtonUp
when "LEFTDOUBLECLICK"
sendLButtonDown
sleep x
sendLButtonUp
sleep y
sendLButtonDown
sleep x
sendLButtonUp
when "MIDDLEDOUBLECLICK"
sendMButtonDown
sleep x
sendMButtonUp
sleep y
sendMButtonDown
sleep x
sendMButtonUp
when "RIGHTDOUBLECLICK"
sendRButtonDown
sleep x
sendRButtonUp
sleep y
sendRButtonDown
sleep x
sendRButtonUp
when "ABS"
mouseMoveAbsPix(x,y)
when "REL"
pos=getCursorPos
mouseMoveAbsPix(pos[0]+x,pos[1]+y)
when "WHEEL"
mouseMoveWheel(w)
else
end
end
def mouseMoveAbsPix(x,y)
@setCursorPosAPI.call(x, y)
end
def mouseMoveWheel(w)
@mouseEventAPI.call(MOUSEEVENTF_WHEEL,0,0,w,0)
end
def findWindowLike(title)
findWindowLikeName(title)
end
def findWindowLikeName(title)
wins=[]
@enumWindowsProc=DL.callback('IL') do |hwnd|
buf=" "*1024
@getWindowTextAPI.call(hwnd,buf,buf.size)
wins << [hwnd, buf.sub(/\0.+$/,'')] if /#{title}/=~buf
-1
end
@enumWindows.call(@enumWindowsProc, 0)
DL.remove_callback(@enumWindowsProc)
wins
end
def findChildWindowLikeName(title)
hwnds=[]
@enumWindowsProc=DL.callback('IL') do |hwnd|
hwnds<< hwnd
-1
end
@enumWindows.call(@enumWindowsProc, 0)
wins=[]
@enumChildWindowsProc=DL.callback('IL') do |hwnd|
buf=" "*1024
@getWindowTextAPI.call(hwnd,buf,buf.size)
wins << [hwnd, buf.sub(/\0.+$/,'')] if /#{title}/=~buf
-1
end
hwnds.each do |hwnd|
@enumChildWindows.call(hwnd, @enumChildWindowsProc, 0)
end
DL.remove_callback(@enumWindowsProc)
DL.remove_callback(@enumChildWindowsProc)
wins
end
def findWindowLikeClass(classname)
hwnds=[]
@enumWindowsProc=DL.callback('IL') do |hwnd|
hwnds<< hwnd
-1
end
@enumWindows.call(@enumWindowsProc, 0)
wins=[]
@enumChildWindowsProc=DL.callback('IL') do |hwnd|
buf=" "*1024
@getClassNameAPI.call(hwnd,buf,buf.size)
wins << [hwnd, buf.sub(/\0.+$/,'')] if /#{classname}/=~buf
-1
end
hwnds.each do |hwnd|
@enumChildWindows.call(hwnd, @enumChildWindowsProc, 0)
end
DL.remove_callback(@enumWindowsProc)
DL.remove_callback(@enumChildWindowsProc)
wins
end
def setForegroundWindow(hwnd)
@setForegroundWindowAPI.call(hwnd)
end
def setFocus(hwnd)
@setFocusAPI.call(hwnd)
end
def getCursorPos
lpP=" "*8
@getCursorPosAPI.Call(lpP)
lpP.unpack("LL")
end
def mouseEvent(event,x=0,y=0,w=0)
@mouseEventAPI.call(event,x,y,w,0)
end
def sendLButtonUp
mouseEvent(MOUSEEVENTF_LEFTUP)
end
def sendLButtonDown
mouseEvent(MOUSEEVENTF_LEFTDOWN)
end
def sendMButtonUp
mouseEvent(MOUSEEVENTF_MIDDLEUP)
end
def sendMButtonDown
mouseEvent(MOUSEEVENTF_MIDDLEDOWN)
end
def sendRButtonUp
mouseEvent(MOUSEEVENTF_RIGHTUP)
end
def sendRButtonDown
mouseEvent(MOUSEEVENTF_RIGHTDOWN)
end
def sendMouseMoveRel(x,y)
sendMouse('REL',x,y)
end
def sendMouseMoveAbs(x,y)
sendMouse('ABS',x,y)
end
def getForegroundWindow
@getForegroundWindowAPI.call
end
def getWindowRect(hwnd)
lpP=" "*16
@getWindowRectAPI.call(hwnd,lpP)
lpP.unpack("LLLL")
end
def moveWindow(hwnd,x=0,y=0,width=500,height=500,repaint=1)
@moveWindowAPI.call(hwnd,x,y,width,height,repaint)
end
def pushButton(button, delay=1)
pushChildButton(getForegroundWindow, button, delay)
end
def pushChildButton(parent, button, delay=1)
setForegroundWindow(parent)
sleep delay
hwnd=findWindowLikeName(button).first[0]
postMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, 0)
sleep 0.5
postMessage(hwnd, WM_LBUTTONUP, 0, 0)
end
def sendMessage(hwnd,msg,wparam,lparam)
@sendMessageAPI.call(hwnd,msg,wparam,lparam)
end
def postMessage(hwnd,msg,wparam,lparam)
@postMessageAPI.call(hwnd,msg,wparam,lparam)
end
def getTopWindow(hwnd)
@getTopWindowAPI.call(hwnd)
end
def cdAudioDoorOpen
@mciSendStringAPI.call('set cdaudio door open')
end
def cdAudioDoorClose
@mciSendStringAPI.call('set cdaudio door closed')
end
def playSound(file)
@playSoundAPI.call(file,nil,0)
end
def getKeyState(key)
@getKeyStateAPI.call(key)
end
def getAsyncKeyState(key)
@getAsyncKeyStateAPI.call(key)
end
def getKeyboardState
lpP=" "*257
@getKeyboardStateAPI.call(lpP)
lpP
end
def Win32GuiTest.convertPerlScript(path)
isAlt=false
isShift=false
isCtrl=false
puts "require 'win32GuiTest'"
puts "gui=Win32GuiTest.new"
puts ""
puts "sleep 5"
puts ""
open(path) do |f|
f.each do |line|
if /^#[^!]+.+$/=~line
puts line
else
puts "sleep #{$1}" if /^select\(undef, undef, undef, (.+?)\);$/=~line
puts "gui.mouseMoveAbsPix(#{$1},#{$2})" if /^MouseMoveAbsPix\((\d.+), (\d.+)\);$/=~line
puts "gui.sendMouse(\"#{$1}\")" if /^SendMouse\('\{(.+?)\}'\);$/=~line
isCtrl = true if /^SendRawKey\(VK_LCONTROL, KEYEVENTF_EXTENDEDKEY\);/=~line
isCtrl = false if /^SendRawKey\(VK_LCONTROL, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP\);/=~line
isAlt = true if /^SendRawKey\(VK_LMENU, KEYEVENTF_EXTENDEDKEY\);/=~line
isAlt = false if /^SendRawKey\(VK_LMENU, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP\);/=~line
isShift = true if /^SendRawKey\(VK_LSHIFT, KEYEVENTF_EXTENDEDKEY\);/=~line
isShift = false if /^SendRawKey\(VK_LSHIFT, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP\);/=~line
if /^SendKeys\('(.+?)'\);$/=~line
texts=$1
texts.gsub!('{BAC}','{BACKSPACE}')
texts.gsub!('{SPC}',' ')
texts.gsub!('{ENT}','{ENTER}')
texts.gsub!('{LEF}','{LEFT}')
texts.gsub!('{RIG}','{RIGHT}')
texts.gsub!('{DOW}','{DOWN}')
if isCtrl || isAlt || isShift
puts "gui.sendKeys('\^\(#{texts}\)')" if isCtrl
puts "gui.sendKeys('\%\(#{texts}\)')" if isAlt
puts "gui.sendKeys('\+\(#{texts}\)')" if isShift
else
puts "gui.sendKeys('#{texts}')"
end
end
end
end
end
end
def Win32GuiTest.bmp2texts(file)
# using Microsoft Office Document Imaging Library (MODI)
doc=WIN32OLE.new('MODI.Document')
doc.Create(file)
doc.OCR(17, false, false) # Japanese
img=doc.Images(0)
layout=img.Layout
str=layout.Text
doc.Close
return str
end
def Win32GuiTest.img2PPTbyOCR(file,texts,title='')
powerPoint=WIN32OLE.new("PowerPoint.Application")
powerPoint.visible=true
ppt=powerPoint.Presentations.Open( \
WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName("ocrmaster.ppt"))
ppt.Slides(1).Shapes(1).TextFrame.TextRange.Text=title
ppt.Slides(1).Shapes(2).TextFrame.TextRange.Text=texts
ppt.SaveAs(WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file))
powerPoint.Quit
end
def Win32GuiTest.jpg2wmf(file,del=false)
f=Win32GuiTest.jpg2bmp(file,false)
f=Win32GuiTest.bmp2pbm(f)
f=Win32GuiTest.pbm2eps(f)
return Win32GuiTest.eps2wmf(f)
end
def Win32GuiTest.jpg2bmp(file,del=true)
output=file.sub(/\.jpg$/i,'.bmp')
command="apps\\JPG2BMP.EXE "+file+' '+output
`#{command}`
File.delete(file) if del
return output
end
def Win32GuiTest.bmp2pbm(file,del=true)
command="apps\\mkbitmap.exe "+file
`#{command}`
File.delete(file) if del
return file.sub(/\.bmp$/i,'.pbm')
end
def Win32GuiTest.pbm2eps(file,del=true)
command="apps\\potrace.exe "+file
`#{command}`
File.delete(file) if del
return file.sub(/\.pbm$/i,'.eps')
end
def Win32GuiTest.eps2wmf(file,del=true)
output=file.sub(/.eps$/i,'.wmf')
command="apps\\pstoedit.exe -f emf "+file+" "+output
`#{command}`
File.delete(file) if del
return file.sub(/\.eps$/i,'.wmf')
end
def Win32GuiTest.img2PPT(file,wmf,del=true)
powerPoint=WIN32OLE.new("PowerPoint.Application")
powerPoint.visible=true
ppt=powerPoint.Presentations.Open( \
WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName("master.ppt"))
ppt.Slides(1).Shapes.AddPicture(WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(wmf),
false, true,260,200,400,300)
ppt.Slides(1).Shapes.each {|shape|
if shape.TextFrame.HasText != 0
s=shape.TextFrame.TextRange.Text
shape.TextFrame.TextRange.Text=s.sub('name',wmf.sub(/\.wmf$/i,''))
end
}
ppt.SaveAs(WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file))
powerPoint.Quit
File.delete(wmf) if del
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment