使用c++从活动窗口获取选定文本
Acquiring selected text from active window using c++
我有下面的代码,我试图从活动窗口获得选定的文本,并将其打印到控制台上。
DWORD new12=0;
KEYBDINPUT* input = new KEYBDINPUT[key_count];
if( GetGUIThreadInfo( new12, lpgui ) )
{
target_window = lpgui->hwndFocus;
}
else
{
// You can get more information on why the function failed by calling
// the win32 function, GetLastError().
std::cout<<"error1";
}
// We're sending two keys CONTROL and 'V'. Since keydown and keyup are two
// seperate messages, we multiply that number by two.
for( int i = 0; i < key_count; i++ )
{
input[i].dwFlags = 0;
//input[i].type = INPUT_KEYBOARD;
}
input[0].wVk = VK_CONTROL;
input[0].wScan = MapVirtualKey( VK_CONTROL, MAPVK_VK_TO_VSC );
input[1].wVk = 0x56; // Virtual key code for 'v'
input[1].wScan = MapVirtualKey( 0x56, MAPVK_VK_TO_VSC );
我有上面的c++代码,但它似乎在input[0].wScan = MapVirtualKey( VK_CONTROL, MAPVK_VK_TO_VSC );
行中给出了一个错误说"error: MAPVK_VK_TO_VSC' was not declared in this scope
"我想知道这里有什么问题。我不认为这个错误是由于任何声明问题而弹出的。你能帮我一下吗?谢谢你。
MAPVK_VK_TO_VSC是一个简单的#define MAPVK_VK_TO_VSC (0)
,甚至不是一个常数,所以它应该在预处理阶段解决。
要么你错过了包括"winuser.h"在这段代码之前(在这种情况下MapVirtualKey和VK_常量将未声明),或者你有未定义的WIN_VER某处(或定义它小于0x400)。有时很容易忘记WIN_VER必须以十六进制定义,并且使用#define WINVER 500,您的版本小于2.0
相关文章:
- 如何从QToolBox中动态创建的QLineEdit中获取文本
- C++文本文件的获取线
- 如何在QGridLayout中获取QComboBox的当前文本?
- 从我的 2DgridArray 中的文本文件中获取每个字符
- 如何在 c++ 中从文本文件中获取特定单词?
- 如何从 winapi 中的编辑表单获取文本?
- 我可以使用谷歌 v8 在回调函数中获取 JavaScript 函数C++源文本吗?
- 我无法将数据从数据网格列传输到 C# 中的数组以获取文本框建议收集数据
- 提升获取文本的区域设置"Conversion failed"
- 获取要从文本文件中读取的行
- 如何使用 FGETS 获取文本,并保存 std::string
- 如果给定了文本样式,如何获取特定文本的 QSize 对象
- 正则表达式 获取两个换行符之间的文本
- 获取文本频繁的语言切换
- 有没有办法将 getline() 与外部文本文件一起使用,然后重新获得 cin 的控制权以从控制台获取输入?
- 编码大于原始文本:如何获取零和一的字符串并将它们作为实际字节写入文件
- Qt - 在QGraphicScene中拖放时如何从项目中获取文本?
- ID3DXFont :文本被拉伸,如何获取字体的宽度和高度?
- 从 Qtabewidgetitem 中更改的文本获取文本 qtablewidget
- 如何使用文本获取选择 - RichEditBox C++