#uselib "user32.dll" #func keybd_event "keybd_event" int, int, int #func mouse_event "mouse_event" int, int, int bgscr 1,100,60,,0,0 mouse_left_pushed=0 mouse_right_pushed=0 key=0 mouse_left=0 mouse_right=0 buf="" dim record position=0 *index title "index" gsel 1,2 width 100,60 cls objsize 100,20 button "REC START",*rec objsize 100,20 button "PLAY START",*play objsize 100,20 button "FINISH",*finish dim record position=0 stop *rec title "rec" gsel 1,2 width 100,20 cls objsize 100,20 button "REC FINISH",*rec_finish repeat pushed_key=0//押されているキー番号を格納する repeat 119 getkey key,cnt+3 if(key=1){ pushed_key=cnt+3 break } loop record(position)="<Event>"+"<Msg>"+"MOVE"+"</Msg>"+"<X>"+str(ginfo(0))+"</X>"+"<Y>"+str(ginfo(1))+"</Y>"+"<Key>"+pushed_key+"</Key>"+"</Event>" getkey mouse_left,1 //L_DOWN if(mouse_left=1 && mouse_left_pushed=0){ mouse_left_pushed=1 record(position)="<Event>"+"<Msg>"+"L_DOWN"+"</Msg>"+"<X>"+str(ginfo(0))+"</X>"+"<Y>"+str(ginfo(1))+"</Y>"+"<Key>"+pushed_key+"</Key>"+"</Event>" } //L_UP if(mouse_left=0 && mouse_left_pushed=1){ mouse_left_pushed=0 record(position)="<Event>"+"<Msg>"+"L_UP"+"</Msg>"+"<X>"+str(ginfo(0))+"</X>"+"<Y>"+str(ginfo(1))+"</Y>"+"<Key>"+pushed_key+"</Key>"+"</Event>" } getkey mouse_right,2 //R_DOWN if(mouse_right=1 && mouse_right_pushed=0){ mouse_right_pushed=1 record(position)="<Event>"+"<Msg>"+"R_DOWN"+"</Msg>"+"<X>"+str(ginfo(0))+"</X>"+"<Y>"+str(ginfo(1))+"</Y>"+"<Key>"+pushed_key+"</Key>"+"</Event>" } //R_UP if(mouse_right=0 && mouse_right_pushed=1){ mouse_right_pushed=0 record(position)="<Event>"+"<Msg>"+"R_UP"+"</Msg>"+"<X>"+str(ginfo(0))+"</X>"+"<Y>"+str(ginfo(1))+"</Y>"+"<Key>"+pushed_key+"</Key>"+"</Event>" } position++ await 5 loop stop *rec_finish title "rec_finish" gosub *save goto *index stop *play title "play" gosub *load prev_key=0//前回のループで押されたキー番号を格納する gsel 1,2 width 100,20 cls objsize 100,20 button "PLAY FINISH",*play_finish repeat length(record) first=instr(record(cnt),0,"<Msg>")+strlen("<Msg>") last=instr(record(cnt),0,"</Msg>") msg=strmid(record(cnt),first,last-first) first=instr(record(cnt),0,"<X>")+strlen("<X>") last=instr(record(cnt),0,"</X>") x=int(strmid(record(cnt),first,last-first)) first=instr(record(cnt),0,"<Y>")+strlen("<Y>") last=instr(record(cnt),0,"</Y>") y=int(strmid(record(cnt),first,last-first)) first=instr(record(cnt),0,"<Key>")+strlen("<Key>") last=instr(record(cnt),0,"</Key>") current_key=int(strmid(record(cnt),first,last-first)) if(msg="MOVE"){ mouse x,y } if(msg="L_DOWN"){ mouse x,y mouse_event $2,0,0 } if(msg="L_UP"){ mouse x,y mouse_event $4,0,0 } if(msg="R_DOWN"){ mouse x,y mouse_event $8,0,0 } if(msg="R_UP"){ mouse x,y mouse_event $10,0,0 } if(prev_key!=current_key){ if(current_key>2){ keybd_event current_key,-1 } prev_key=current_key } await 5 loop *play_finish title "play_finish" goto *index stop *save notesel buf buf="" repeat length(record) noteadd str(record(cnt)) loop notesave "record.txt" return *load notesel buf buf="" noteload "record.txt" repeat noteinfo(0) noteget record(cnt),cnt loop return *finish end
少し長くてすみません。
このようなコードで、現在キー操作とマウス操作の記録を行っています。
記録が上手くいくこともあるのですが、たまに「a」と打ったのになぜか「d」になったり、よく分からないバグが起こってしまいます。
何度も見直したのですが、なかなか原因が特定できず・・・。(上手くいくことがあるだけに)
マウス操作の部分は記録できています。
キー操作の部分でなにかおかしい部分があればご指摘お願いします!