背景:
在我使用 Windows API 进行开发的大部分时间里,我一直在分别使用
感谢这个网站,键盘实现完美无缺
但是,我现在将注意力转向实现鼠标移动。据我了解,
问题是我还想在类中存储鼠标指针的客户端和屏幕空间坐标,理想情况下我想这样做而不需要同时捕获
我对
Note that the values returned are not screen space values like you get from the WM_MOUSEMOVE message. This is raw data we are getting so the values need interpreting.
这让我相信可以通过使用初始调用
// Somewhere in class header
RECT m_screenMouseBounds;
POINT m_mouseDelta;
POINT m_mouseScreenPosition;
POINT m_mouseScreenPositionGETCURSOR;
RAWMOUSE m_rawMouse;
// ...
// Somewhere during class initialisation
GetCursorPos(&m_mouseScreenPosition); // Get initial mouse cursor position
// Determine maximum and minimum boundaires of current display
m_screenMouseBounds.right = GetSystemMetrics(SM_CXSCREEN);
m_screenMouseBounds.bottom = GetSystemMetrics(SM_CYSCREEN);
m_screenMouseBounds.top = 0;
m_screenMouseBounds.left = 0;
// Prepare the devices for registering
RAWINPUTDEVICE theInputDevices[2];
// 0 = keyboard
theInputDevices[0].usUsagePage = 0x01;
theInputDevices[0].usUsage = 0x06;
theInputDevices[0].dwFlags = RIDEV_NOLEGACY;
theInputDevices[0].hwndTarget = theWindowToHandle;
// 1 = mouse
theInputDevices[1].usUsagePage = 0x01;
theInputDevices[1].usUsage = 0x02;
theInputDevices[1].dwFlags = 0; // RIDEV_NOLEGACY
theInputDevices[1].hwndTarget = theWindowToHandle;
// Register each device with raw input
if(RegisterRawInputDevices(theInputDevices,2,sizeof(RAWINPUTDEVICE))==FALSE)
{
// throw exception
return false;
}
// ...
// In the WM_INPUT processing function with parameters : (WPARAM wParam, LPARAM lParam)
char inputBuffer[sizeof(RAWINPUT)] = {};
UINT inputBufferSize = sizeof(RAWINPUT);
GetRawInputData(reinterpret_cast<HRAWINPUT>(lParam), RID_INPUT, inputBuffer, &inputBufferSize, sizeof(RAWINPUTHEADER));
RAWINPUT* rawData = reinterpret_cast<RAWINPUT*>(inputBuffer);
if(rawData->header.dwType == RIM_TYPEMOUSE)
{
m_rawMouse = rawData->data.mouse;
// Add the movement deltas acquired from the WM_INPUT message
m_mouseDelta.x = m_rawMouse.lLastX;
m_mouseDelta.y = m_rawMouse.lLastY;
// Update the screen position using the delta values (Does not work as expected!)
m_mouseScreenPosition.x += m_mouseDelta.x;
m_mouseScreenPosition.y += m_mouseDelta.y;
// Ensure mouse coords are within the screens boundaries
if (m_mouseScreenPosition.x < m_screenMouseBounds.left)
{
m_mouseScreenPosition.x = m_screenMouseBounds.left;
}
if (m_mouseScreenPosition.x > m_screenMouseBounds.right)
{
m_mouseScreenPosition.x = m_screenMouseBounds.right;
}
if (m_mouseScreenPosition.y < m_screenMouseBounds.top)
{
m_mouseScreenPosition.y = m_screenMouseBounds.top;
}
if (m_mouseScreenPosition.y > m_screenMouseBounds.bottom)
{
m_mouseScreenPosition.y = m_screenMouseBounds.bottom;
}
// Double check to make sure that the screen position coordinates calculated
// above match the screen coordinates as determined by Windows
// using GetCursorPos() (Hint: They don't! :( )
GetCursorPos(&m_mouseScreenPositionGETCURSOR);
TCHAR s[256];
swprintf(s, L"MouseDX: %ld MouseDY: %ld\
", m_mouseDelta.x, m_mouseDelta.y);
OutputDebugString(s);
swprintf(s, L"MouseX(Screen(WM_INPUT)): %ld MouseY(Screen(WM_INPUT)): %ld\
", m_mouseScreenPosition.x, m_mouseScreenPosition.y);
OutputDebugString(s);
swprintf(s, L"MouseX(Screen(GetCursorPos)): %ld MouseY(Screen(GetCursorPos)): %ld\
", m_mouseScreenPositionGETCURSOR.x, m_mouseScreenPositionGETCURSOR.y);
OutputDebugString(s);
}问题是通过这种方法为
总结
我想我的全部问题是:
如果1的答案与鼠标有关而不是显示坐标:是否可以仅使用
如果 2 的答案是,我将需要使用
如果你已经做到了这一点,我非常感谢你,我很感激你能给我的任何帮助或信息。谢谢!
"请注意,返回的值不是您从 WM_MOUSEMOVE 消息中获得的屏幕空间值。这是我们获得的原始数据,因此需要解释这些值。这些值通常与最后一个位置相关,因此表示运动。确保您可以检查 RAWMOUSE 结构中的 usFlags。"从玩具制造商那里得到这个,我总是觉得很棒。这里
RAWINPUT 仅用于获取相对输入。这就是为什么它是生的。如果您真的不想使用 GetCursorPos,只需使用 WM_MOUSEMOVE 并检查 l/w 参数。
我实际上从未对 GetCursorPos() 进行过性能测试,但我已经为我自己的项目阅读了一些关于它的内容,并且从未看到任何反对意见。调用 GetCursorPos,无论您是否使用 RAWINPUT,每帧一次或每次更新都肯定可以忽略不计。我用它来旋转相机,它一直工作得很好。
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
由于fast-stemmer的问题,我很难安装我想要的任何rubygem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=
我有用于控制用户任务的Rails5API项目,我有以下错误,但并非总是针对相同的Controller和路由。ActionController::RoutingError:uninitializedconstantApi::V1::ApiController我向您描述了一些我的项目,以更详细地解释错误。应用结构路线scopemodule:'api'donamespace:v1do#=>Loginroutesscopemodule:'login'domatch'login',to:'sessions#login',as:'login',via::postend#=>Teamroutessc
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我意识到这可能是一个非常基本的问题,但我现在已经花了几天时间回过头来解决这个问题,但出于某种原因,Google就是没有帮助我。(我认为部分问题在于我是一个初学者,我不知道该问什么......)我也看过O'Reilly的RubyCookbook和RailsAPI,但我仍然停留在这个问题上.我找到了一些关于多态关系的信息,但它似乎不是我需要的(尽管如果我错了请告诉我)。我正在尝试调整MichaelHartl'stutorial创建一个包含用户、文章和评论的博客应用程序(不使用脚手架)。我希望评论既属于用户又属于文章。我的主要问题是:我不知道如何将当前文章的ID放入评论Controller。
给定一个复杂的对象层次结构,幸运的是它不包含循环引用,我如何实现支持各种格式的序列化?我不是来讨论实际实现的。相反,我正在寻找可能会派上用场的设计模式提示。更准确地说:我正在使用Ruby,我想解析XML和JSON数据以构建复杂的对象层次结构。此外,应该可以将该层次结构序列化为JSON、XML和可能的HTML。我可以为此使用Builder模式吗?在任何提到的情况下,我都有某种结构化数据-无论是在内存中还是文本中-我想用它来构建其他东西。我认为将序列化逻辑与实际业务逻辑分开会很好,这样我以后就可以轻松支持多种XML格式。 最佳答案 我最
首先回顾一下拉格朗日定理的内容:函数f(x)是在闭区间[a,b]上连续、开区间(a,b)上可导的函数,那么至少存在一个,使得:通过这个表达式我们可以知道,f(x)是函数的主体,a和b可以看作是主体函数f(x)中所取的两个值。那么可以有, 也就意味着我们可以用来替换 这种替换可以用在求某些多项式差的极限中。方法: 外层函数f(x)是一致的,并且h(x)和g(x)是等价无穷小。此时,利用拉格朗日定理,将原式替换为 ,再进行求解,往往会省去复合函数求极限的很多麻烦。使用要注意:1.要先找到主体函数f(x),即外层函数必须相同。2.f(x)找到后,复合部分是等价无穷小。3.要满足作差的形式。如果是加