启动程序中的GetAsyncKeyState(Windows 7) [英] GetAsyncKeyState in Startup program (Windows 7)

查看:99
本文介绍了启动程序中的GetAsyncKeyState(Windows 7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为我会很聪明并且在我的Startup文件夹中有一个程序检查是否按下了shift键并执行了不同的操作。  (比如进入维护/服务模式。) 此程序放在我的启动文件夹中,以便在我登录时自动运行

I thought I would be clever and have a program in my Startup folder check to see if the shift key is being held down and do something different.  (Like enter a maintenance/service mode.)  This program is placed in my startup folder so that it runs automatically when I log in.

令我惊讶,GetAsyncKeyState(VK_SHIFT)&如果程序被放置在我的启动文件夹中运行,0x8000总是为零,无论我是否按住shift键。  如果我在登录时按住shift键,或者在
系统启动时没关系,就像登录的行为似乎重置了键盘状态。  如果我通过双击,或从命令行启动它,或从其他进程启动它,程序将正常运行。  在我登录之前,如果按下shift键,
键盘似乎不知道shift键是否已关闭。

To my surprise, GetAsyncKeyState( VK_SHIFT ) & 0x8000 is always zero if the program is placed to run in my startup folder, whether I'm holding down the shift key or not.  It doesn't matter if I hold down the shift key while logging in, or while the system is starting up, it's like the act of logging in seems to reset the keyboard state.  The program runs normally if I launch it by double-clicking, or from the command line, or launched from another process.  It really seems to be like the keyboard doesn't know that the shift key is down if the shift key was pressed before I logged in.

任何人都可以告诉我如何获得我想要的功能(真的,真的,真的检测到shift键是否关闭)和
它必须适用于Windows 7中我的启动文件夹中的程序。  (我登录时自动运行的程序。)

Can anyone tell me how to get the functionality I want (really, truly detect if the shift key is down) and it must work for a program that is in my startup folder in Windows 7.  (A program that runs automatically when I log in.)

如果使用GetAsyncKeyState不可能,有人可以建议替代方案吗?

If it's not possible using GetAsyncKeyState, can someone please suggest an alternative?

推荐答案

Hi Wyck,

Hi Wyck,

欢迎光临。

根据我的理解,如果我们不这样做登录,也许我们无法加载自定义的应用程序。

Based on my understanding, if we do not logon, maybe we cannot load the self-defined application.

请参阅链接:
会话0隔离

从以上链接引用:

在Windows XP,Windows Server 2003和早期版本的Windows操作系统中,服务和应用程序在与登录控制台的第一个用户启动的会话中运行。此会话称为会话0.

In Windows XP, Windows Server 2003, and earlier versions of the Windows operating system, services and applications run in the same session as the one started by the first user who logs onto the console. This session is called Session 0.

从Windows Vista开始,只有服务在会话0中托管。用户应用程序与服务隔离,并在后续会话中运行用户登录系统时创建:第一个登录用户的会话1,第二个登录用户的会话2,以及
等等。

Starting with Windows Vista, only services are hosted in Session 0. User applications are isolated from services, and run in subsequent sessions created when users log onto the system: Session 1 for the first logged on user, Session 2 for the second, and so on.

我希望这个链接可以帮助你。

I hope the link helps you.

问候,


这篇关于启动程序中的GetAsyncKeyState(Windows 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆