7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++とWin32APIでマウスを押したりホイールをまわしたり

Posted at
tmp.h
void	lclick(int x,int y){
	SetCursorPos(x,y);
	mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
	mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}
void	rclick(int x,int y){
	SetCursorPos(x,y);
	mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
	mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
}
void	wheel(int w){
	mouse_event(MOUSEEVENTF_WHEEL,0,0,w,0);
}

あとは適当にlclick(120,300);等等と書けばカーソルが瞬間移動してスクリーン座標120,300を左クリックしてくれます。
wheel(-100);と書けばウィンドウが下にスクロールします。
他の人はSendInput関数を使う方法を紹介していますが私の環境ではなぜかスクリーンセーバが起動します。意味不明なので上記が堅実です。

7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?