2017-04-21 11 views
0

私は次のコードを持っています。コードを実行すると、マウスポインタが0 0の座標に移動します。私はx1 y1の位置にカーソルを移動する必要があります。 x1 y1の値は整数です。xdotoolコマンドで変数を使用する方法

int x1,y1; 
       for(int i=0; i<nomdef; i++) 
       { 
        if(defectArray[i].depth > 40) 
        { 
         con=con+1; 
         if(con==1) 
         { 
          x1=(defectArray[i].depth_point)->x; 
       y1=(defectArray[i].depth_point)->y; 
         } 
         cvLine(src, *(defectArray[i].start), *(defectArray[i].depth_point),CV_RGB(255,255,0),1, CV_AA, 0); 
         cvCircle(src, *(defectArray[i].depth_point), 5, CV_RGB(0,0,255), 2, 8,0);        cvDrawContours(src,defects,CV_RGB(0,0,0),CV_RGB(255,0,0),-1,CV_FILLED,8); 

        } 
       }system("xdotool mousemove x1 y1"); 

答えて

0

これはC++プログラムです(bashなどの高レベル言語ではありません)。 C/C++の文字列定数には、変数呼び出し/置換はありません。

したがって、システムコールはあなたが書いたものを実行します:"xdotool mousemove x1 y1"を呼び出します(期待通りにx1とy1を置き換えません)。

代わりに、文字列の書式を設定する必要があります。 std::string,std::ostringstreamを使用してください。これは動作するはず

std::ostringstream ossCmd; 
ossCmd << "xdotool mousemove " << x1 << ' ' << y1; 
#if 1 // EXPLICIT: 
std::string cmd = ossCmd.str(); 
system(cmd.c_str()); 
#else // COMBINED: 
system(ossCmd.str().c_str()); 
#endif // 1 

:に

#include <string> 
#include <sstream> 

変更し、あなたのコードの最後の行を:

は、ファイルの先頭にこれらが含まを追加します。

注:

#if 1事は奇妙に見えるかもしれませんが、それは、開発者は、必要に応じて変更されることがあり、その間、アクティブおよび非アクティブコードの選択肢を持っているC/C++での通常の方法です。

関連する問題