windowsのステップを記録しJavaScriptにする。
@@ -1,9 +1,9 @@ | ||
1 | -<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ | |
1 | +<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> | |
2 | 2 | Partial Class Form1 |
3 | 3 | Inherits System.Windows.Forms.Form |
4 | 4 | |
5 | 5 | 'フォームがコンポーネントの一覧をクリーンアップするために dispose をオーバーライドします。 |
6 | - <System.Diagnostics.DebuggerNonUserCode()> _ | |
6 | + <System.Diagnostics.DebuggerNonUserCode()> | |
7 | 7 | Protected Overrides Sub Dispose(ByVal disposing As Boolean) |
8 | 8 | Try |
9 | 9 | If disposing AndAlso components IsNot Nothing Then |
@@ -20,36 +20,49 @@ | ||
20 | 20 | 'メモ: 以下のプロシージャは Windows フォーム デザイナーで必要です。 |
21 | 21 | 'Windows フォーム デザイナーを使用して変更できます。 |
22 | 22 | 'コード エディターを使って変更しないでください。 |
23 | - <System.Diagnostics.DebuggerStepThrough()> _ | |
23 | + <System.Diagnostics.DebuggerStepThrough()> | |
24 | 24 | Private Sub InitializeComponent() |
25 | + Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1)) | |
25 | 26 | Me.TextBox1 = New System.Windows.Forms.TextBox() |
26 | 27 | Me.btnPlay = New System.Windows.Forms.Button() |
28 | + Me.btnRec = New System.Windows.Forms.Button() | |
27 | 29 | Me.SuspendLayout() |
28 | 30 | ' |
29 | 31 | 'TextBox1 |
30 | 32 | ' |
31 | 33 | Me.TextBox1.Dock = System.Windows.Forms.DockStyle.Bottom |
32 | - Me.TextBox1.Location = New System.Drawing.Point(0, 59) | |
34 | + Me.TextBox1.Location = New System.Drawing.Point(0, 53) | |
33 | 35 | Me.TextBox1.Multiline = True |
34 | 36 | Me.TextBox1.Name = "TextBox1" |
35 | - Me.TextBox1.Size = New System.Drawing.Size(282, 194) | |
37 | + Me.TextBox1.Size = New System.Drawing.Size(798, 459) | |
36 | 38 | Me.TextBox1.TabIndex = 0 |
37 | - Me.TextBox1.Text = "WScript.Echo(""hello world"")" | |
39 | + Me.TextBox1.Text = resources.GetString("TextBox1.Text") | |
38 | 40 | ' |
39 | 41 | 'btnPlay |
40 | 42 | ' |
41 | - Me.btnPlay.Location = New System.Drawing.Point(100, 21) | |
43 | + Me.btnPlay.Font = New System.Drawing.Font("MS UI Gothic", 13.8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte)) | |
44 | + Me.btnPlay.Location = New System.Drawing.Point(124, 12) | |
42 | 45 | Me.btnPlay.Name = "btnPlay" |
43 | - Me.btnPlay.Size = New System.Drawing.Size(75, 23) | |
46 | + Me.btnPlay.Size = New System.Drawing.Size(38, 35) | |
44 | 47 | Me.btnPlay.TabIndex = 1 |
45 | - Me.btnPlay.Text = "再生" | |
48 | + Me.btnPlay.Text = "▶" | |
46 | 49 | Me.btnPlay.UseVisualStyleBackColor = True |
47 | 50 | ' |
51 | + 'btnRec | |
52 | + ' | |
53 | + Me.btnRec.Location = New System.Drawing.Point(79, 12) | |
54 | + Me.btnRec.Name = "btnRec" | |
55 | + Me.btnRec.Size = New System.Drawing.Size(39, 35) | |
56 | + Me.btnRec.TabIndex = 2 | |
57 | + Me.btnRec.Text = "●" | |
58 | + Me.btnRec.UseVisualStyleBackColor = True | |
59 | + ' | |
48 | 60 | 'Form1 |
49 | 61 | ' |
50 | 62 | Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 15.0!) |
51 | 63 | Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font |
52 | - Me.ClientSize = New System.Drawing.Size(282, 253) | |
64 | + Me.ClientSize = New System.Drawing.Size(798, 512) | |
65 | + Me.Controls.Add(Me.btnRec) | |
53 | 66 | Me.Controls.Add(Me.btnPlay) |
54 | 67 | Me.Controls.Add(Me.TextBox1) |
55 | 68 | Me.Name = "Form1" |
@@ -61,4 +74,5 @@ | ||
61 | 74 | |
62 | 75 | Friend WithEvents TextBox1 As TextBox |
63 | 76 | Friend WithEvents btnPlay As Button |
77 | + Friend WithEvents btnRec As Button | |
64 | 78 | End Class |
@@ -1,4 +1,11 @@ | ||
1 | -Public Class Form1 | |
1 | +Imports System.ComponentModel | |
2 | + | |
3 | +Public Class Form1 | |
4 | + | |
5 | + Private isRec As Boolean = False | |
6 | + | |
7 | + Private WithEvents MouseHook As New MouseHookClass | |
8 | + | |
2 | 9 | Private Sub btnPlay_Click(sender As Object, e As EventArgs) Handles btnPlay.Click |
3 | 10 | Dim jsfilename As String |
4 | 11 | 'ファイル名がない場合はuntitle.jsに保存する。 |
@@ -8,7 +15,59 @@ | ||
8 | 15 | End Using |
9 | 16 | |
10 | 17 | 'untitle.jsを実行する |
11 | - Dim p As Process = System.Diagnostics.Process.Start(jsfilename) | |
18 | + Dim p = System.Diagnostics.Process.Start(jsfilename) | |
12 | 19 | |
13 | 20 | End Sub |
21 | + | |
22 | + Private Sub btnRec_Click(sender As Object, e As EventArgs) Handles btnRec.Click | |
23 | + isRec = Not isRec | |
24 | + btnRecView() | |
25 | + If isRec Then | |
26 | + MouseHook.MouseHookStart() | |
27 | + Else | |
28 | + MouseHook.MouseHookEnd() | |
29 | + End If | |
30 | + End Sub | |
31 | + | |
32 | + Private Sub btnRecView() | |
33 | + If isRec Then | |
34 | + btnRec.Text = "■" | |
35 | + Else | |
36 | + btnRec.Text = "●" | |
37 | + End If | |
38 | + btnPlay.Enabled = Not isRec | |
39 | + End Sub | |
40 | + | |
41 | + Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load | |
42 | + btnRecView() | |
43 | + TextBox1.SelectionLength = 0 | |
44 | + End Sub | |
45 | + | |
46 | + Private Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing | |
47 | + If MouseHook.Hooked = True Then | |
48 | + MouseHook.MouseHookEnd() | |
49 | + End If | |
50 | + End Sub | |
51 | + | |
52 | + Private Sub MouseHook_MouseHook(sender As Object, e As MouseHookClass.MouseHookEventArgs) Handles MouseHook.MouseHook | |
53 | + 'カレットの位置を取得 | |
54 | + Dim selectPos As Integer = TextBox1.SelectionStart | |
55 | + InsertMouseMove(e.Point.x, e.Point.y, e.Message) | |
56 | + 'カーソルを戻す | |
57 | + Me.TextBox1.SelectionStart = selectPos | |
58 | + | |
59 | + End Sub | |
60 | + | |
61 | + Private Sub InsertMouseMove(x As Integer, y As Integer, message As MouseHookClass.MouseMessage) | |
62 | + Dim code As String = String.Empty | |
63 | + If message = MouseHookClass.MouseMessage.Move Then | |
64 | + code = $" sh.Run(""rundll32.exe MouseEmulator.dll, _SetMouseXY@16 {x}, {y}"");" | |
65 | + End If | |
66 | + | |
67 | + TextBox1.SelectedText = code | |
68 | + End Sub | |
69 | + | |
70 | + Private Sub Button1_Click(sender As Object, e As EventArgs) | |
71 | + | |
72 | + End Sub | |
14 | 73 | End Class |
@@ -0,0 +1,168 @@ | ||
1 | +Imports System.Runtime.InteropServices | |
2 | +Public Delegate Function CallBack(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer | |
3 | + | |
4 | +Public Class MouseHookClass | |
5 | + | |
6 | + Dim WH_MOUSE_LL As Integer = 14 | |
7 | + Shared hHook As Integer = 0 | |
8 | + | |
9 | + Private hookproc As CallBack | |
10 | + | |
11 | + <DllImport("kernel32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> | |
12 | + Public Overloads Shared Function GetModuleHandle(lpModuleName As String) As IntPtr | |
13 | + End Function | |
14 | + | |
15 | + 'Import for the SetWindowsHookEx function. | |
16 | + <DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> | |
17 | + Public Overloads Shared Function SetWindowsHookEx(ByVal idHook As Integer, ByVal HookProc As CallBack, ByVal hInstance As IntPtr, ByVal wParam As Integer) As Integer | |
18 | + End Function | |
19 | + | |
20 | + 'Import for the CallNextHookEx function. | |
21 | + <DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> | |
22 | + Public Overloads Shared Function CallNextHookEx(ByVal idHook As Integer, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer | |
23 | + End Function | |
24 | + 'Import for the UnhookWindowsHookEx function. | |
25 | + <DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> | |
26 | + Public Overloads Shared Function UnhookWindowsHookEx(ByVal idHook As Integer) As Boolean | |
27 | + End Function | |
28 | + | |
29 | + 'Point structure declaration. | |
30 | + <StructLayout(LayoutKind.Sequential)> Public Structure Point | |
31 | + Public x As Integer | |
32 | + Public y As Integer | |
33 | + End Structure | |
34 | + | |
35 | + <StructLayout(LayoutKind.Sequential)> | |
36 | + Public Class MouseLLHookStruct | |
37 | + Public pt As Point | |
38 | + Public mouseData As Integer | |
39 | + Public flags As Integer | |
40 | + Public time As Integer | |
41 | + Public dwExtraInfo As Integer | |
42 | + End Class | |
43 | + | |
44 | + 'マウス操作の種類を表す。 | |
45 | + Public Enum MouseMessage | |
46 | + 'マウスカーソルが移動した。 | |
47 | + Move = &H200 | |
48 | + '左ボタンが押された。 | |
49 | + LDown = &H201 | |
50 | + '左ボタンが解放された。 | |
51 | + LUp = &H202 | |
52 | + '右ボタンが押された。 | |
53 | + RDown = &H204 | |
54 | + '左ボタンが解放された。 | |
55 | + RUp = &H205 | |
56 | + '中ボタンが押された。 | |
57 | + MDown = &H207 | |
58 | + '中ボタンが解放された。 | |
59 | + MUp = &H208 | |
60 | + 'ホイールが回転した。 | |
61 | + Wheel = &H20A | |
62 | + 'Xボタンが押された。 | |
63 | + XDown = &H20B | |
64 | + 'Xボタンが解放された。 | |
65 | + XUp = &H20C | |
66 | + End Enum | |
67 | + | |
68 | + | |
69 | + Public Event MouseHook(sender As Object, e As MouseHookEventArgs) | |
70 | + Public Class MouseHookEventArgs | |
71 | + Inherits EventArgs | |
72 | + | |
73 | + Private _mousestatus As MouseLLHookStruct | |
74 | + Private _mousemessage As MouseMessage | |
75 | + Public Sub New(mousemessage As MouseMessage, mousestatus As MouseLLHookStruct) | |
76 | + _mousemessage = mousemessage | |
77 | + _mousestatus = mousestatus | |
78 | + End Sub | |
79 | + | |
80 | + ''' <summary> | |
81 | + ''' マウスカーソルの位置(スクリーン座標) | |
82 | + ''' </summary> | |
83 | + Public ReadOnly Property Point As Point | |
84 | + Get | |
85 | + Return _mousestatus.pt | |
86 | + End Get | |
87 | + End Property | |
88 | + | |
89 | + ''' <summary> | |
90 | + ''' マウスの状態 | |
91 | + ''' </summary> | |
92 | + Public ReadOnly Property Message As MouseMessage | |
93 | + Get | |
94 | + Return _mousemessage | |
95 | + End Get | |
96 | + End Property | |
97 | + End Class | |
98 | + | |
99 | + | |
100 | + ''' <summary> | |
101 | + ''' 現在マウスをフックしているか返す | |
102 | + ''' </summary> | |
103 | + ''' <returns>False:フックしていない True:フックしている</returns> | |
104 | + ''' <remarks></remarks> | |
105 | + Public ReadOnly Property Hooked As Boolean | |
106 | + Get | |
107 | + Return If(hHook = 0, False, True) | |
108 | + End Get | |
109 | + End Property | |
110 | + | |
111 | + ''' <summary> | |
112 | + ''' マウスフックを開始する | |
113 | + ''' </summary> | |
114 | + ''' <returns>False:フックに失敗もしくはフック済み True:フックに成功</returns> | |
115 | + ''' <remarks></remarks> | |
116 | + Public Function MouseHookStart() As Boolean | |
117 | + If hHook.Equals(0) Then | |
118 | + 'マウスフックを開始する | |
119 | + hookproc = AddressOf MouseLLHookProc | |
120 | + hHook = SetWindowsHookEx(WH_MOUSE_LL, hookproc, GetModuleHandle(CType(IntPtr.Zero, String)), 0) | |
121 | + If hHook.Equals(0) Then | |
122 | + Return False | |
123 | + Else | |
124 | + Return True | |
125 | + End If | |
126 | + Else | |
127 | + 'マウスフックがすでに開始されている | |
128 | + Return False | |
129 | + End If | |
130 | + | |
131 | + End Function | |
132 | + | |
133 | + ''' <summary> | |
134 | + ''' マウスフックを終了する | |
135 | + ''' </summary> | |
136 | + ''' <returns>False:フック解除に失敗もしくはフックしていない True:フック解除に成功</returns> | |
137 | + ''' <remarks></remarks> | |
138 | + Public Function MouseHookEnd() As Boolean | |
139 | + If hHook.Equals(0) Then | |
140 | + 'マウスフックが開始されていない | |
141 | + Return False | |
142 | + Else | |
143 | + 'マウスフックを終了する | |
144 | + Dim ret As Boolean = UnhookWindowsHookEx(hHook) | |
145 | + | |
146 | + If ret.Equals(False) Then | |
147 | + Return False | |
148 | + Else | |
149 | + hHook = 0 | |
150 | + Return True | |
151 | + End If | |
152 | + End If | |
153 | + | |
154 | + End Function | |
155 | + | |
156 | + Private Function MouseLLHookProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer | |
157 | + Dim MyMouseHookStruct As New MouseLLHookStruct() | |
158 | + | |
159 | + If nCode = 0 Then | |
160 | + MyMouseHookStruct = CType(Marshal.PtrToStructure(lParam, MyMouseHookStruct.GetType()), MouseLLHookStruct) | |
161 | + 'イベントを発生させる | |
162 | + RaiseEvent MouseHook(Nothing, New MouseHookEventArgs(CType(wParam, MouseMessage), MyMouseHookStruct)) | |
163 | + End If | |
164 | + | |
165 | + Return CallNextHookEx(hHook, nCode, wParam, lParam) | |
166 | + End Function | |
167 | + | |
168 | +End Class | |
\ No newline at end of file |