Я пытаюсь обнаружить щелчки кнопок мыши. Я проверил документацию на веб-сайте Microsoft и обнаружил, что мы можем использовать функцию GetKeyState для обнаружения щелчков кнопок, вот мой код.
Не уверен, что я делаю не так, но я у меня ничего не печатается в моем выводе, когда я нажимаю кнопки.
#include <windows.h>
#include <iostream>
#include "stdafx.h"
using namespace std;
void CheckMouseButtonStatus()
{
//Check the mouse left button is pressed or not
if ((GetKeyState(VK_LBUTTON) & 0x80) != 0)
{
cout << "left button pressed" << endl;
}
//Check the mouse right button is pressed or not
if ((GetKeyState(VK_RBUTTON) & 0x80) != 0)
{
cout << "right button pressed" << endl;
}
}
только что нашел видео на YouTube, о котором рассказывал приятель, и я попробовал, все равно ничего не было на выходе
int main()
{
//Check the mouse left button is pressed or not
if ((GetAsyncKeyState(VK_LBUTTON) & 0x80) != 0)
{
cout << "left button pressed" << endl;
}
//Check the mouse right button is pressed or not
if ((GetAsyncKeyState(VK_RBUTTON) & 0x80) != 0)
{
cout << "right button pressed" << endl;
}
}
Этот работал, но с некоторыми осложнениями -
int main()
{
while (true) {
//Check the mouse left button is pressed or not
if (GetAsyncKeyState(VK_LBUTTON))
{
cout << "left button pressed" << endl;
}
//Check the mouse right button is pressed or not
if (GetAsyncKeyState(VK_RBUTTON))
{
cout << "right button pressed" << endl;
}
}
}