HSPポータル
サイトマップ お問い合わせ


HSPTV!掲示板


未解決 解決 停止 削除要請

2016
0826
saltマウス操作とキー操作録画3未解決


salt

リンク

2016/8/26(Fri) 10:05:57|NO.76724


#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」になったり、よく分からないバグが起こってしまいます。
何度も見直したのですが、なかなか原因が特定できず・・・。(上手くいくことがあるだけに)
マウス操作の部分は記録できています。
キー操作の部分でなにかおかしい部分があればご指摘お願いします!



この記事に返信する


掘木

リンク

2016/8/26(Fri) 20:34:56|NO.76729

ふーむ。

#uselib "user32.dll" #func keybd_event "keybd_event" int, int, int #func mouse_event "mouse_event" int, int, int
https://msdn.microsoft.com/ja-jp/library/cc410921.aspx
https://msdn.microsoft.com/ja-jp/library/cc364822.aspx
なんでmouse_eventの引数がint3つ分?パッと見5個分あると思うんだけど。
まぁ本件そこを聞いてないから放置で。(原因にかなり近い気がしてならないけど)


提示されたコードを見るに、記録/再現 っていう2段階あって、
記録先にファイルを選択できるようになっているように見える。

記録→保存→(終了)→読込→再現
記録→→→→→→→→→→→→再現
のどちらかのサイクルを試しているように思えますが、
どこまで期待通りの動作をしているのか確認しましたか?
(保存されたファイル開いて確認してるよね?)



MillkeyStars

リンク

2016/8/27(Sat) 12:56:21|NO.76731

入力情報取得部の一部に不明な計算式が存在している。

repeat 119 getkey key,cnt+3 //←なんで +3 ? if(key=1){ pushed_key=cnt+3 //←ここも break } loop

これだと、普通に 「a」が「d」として認識されるのは普通だと思いますが?



MillkeyStars

リンク

2016/8/27(Sat) 13:32:25|NO.76732

掘木さんも言う通りに、命令・関数定義は、必ず MSDN の方法に従って記載してください。
HSP での定義の引数が不足している場合、未初期化の内容が参照されてしまいます。


#uselib "user32.dll" #func keybd_event "keybd_event" int, int, int #func mouse_event "mouse_event" int, int, int


#uselib "user32.dll" #func keybd_event "keybd_event" int, int, int, int #func mouse_event "mouse_event" int, int, int, int,int
にしてください。未初期化の内容がDLL側に送られた場合、動作を保証することができません。
定義がきちんと書いてあれば、命令側は省略する事が可能です。

keybd_event p1,p2,p3,p4,p5 //←本来の書き方 keybd_event p1,p2,p3 //←省略した書き方。この場合 p4,p5 は 0 となる。



ONION software Copyright 1997-2023(c) All rights reserved.