-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccessible_test.cpp
More file actions
86 lines (73 loc) · 2.07 KB
/
accessible_test.cpp
File metadata and controls
86 lines (73 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// windows
#include <windows.h>
#include <oleacc.h>
#include <initguid.h>
// c++
#include <cstdint>
#include <cstdio>
#include <string>
#include <regex>
#include <iostream>
#include <memory>
#include "logger.hpp"
#include "com_ptr.hpp"
#include "interfaces.hpp"
#include "bstr.hpp"
#include "dumper.hpp"
namespace rap
{
void SelectItemAtPoint(int x, int y)
{
try
{
POINT point = {(LONG)x, (LONG)y};
HWND hw = WindowFromPoint(point);
printf("HWND: %p\n", hw);
com_ptr<IAccessible> pIA;
THROW_IF_FAILED(AccessibleObjectFromWindow(hw, OBJID_CLIENT, IID_IAccessible, (void**)&pIA));
dump_ia(pIA);
}
catch(...) {}
}
int main(int argc, char** argv)
{
LOG_IF_FAILED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED));
// event loop
const std::regex pointRegex("^\\s*([0-9]+)\\s*[,]{0,1}\\s*([0-9]+)\\s*$");
puts("Ready!");
for (std::string line; []() -> bool {printf("$ "); return true;}() && std::getline(std::cin, line);)
{
if (line == "quit") {
return 0;
}
if (line == "mouse") {
POINT p;
if (GetCursorPos(&p))
{
printf("POINT : { x : %i, y : %i }\n", (int32_t)p.x, (int32_t)p.y);
SelectItemAtPoint(p.x, p.y);
}
else
{
fprintf(stderr, "Could not read cursor position\n");
}
continue;
}
std::smatch matches;
if (std::regex_match(line, matches, pointRegex))
{
int x = atoi(matches[1].str().c_str());
int y = atoi(matches[2].str().c_str());
SelectItemAtPoint(x, y);
} else
{
fprintf(stderr, "Could not parse '%s' as POINT\n", line.c_str());
}
}
return 0;
}
}
int main(int argc, char** argv)
{
return rap::main(argc, argv);
}