|
since they are handled one at a time, shouldn't GetAsyncKeyState work for what he's trying to do. Since if both keys are down, one had to be pressed first, I would think this should work.
Pseudocode:
if nChar == VK_LEFT
{
If GetAsyncKeyState(VK_DOWN)
DoStuff();
}
if nChar == VK_DOWN
{
If GetAsyncKeyState(VK_LEFT)
DoStuff();
}
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
BlackDice wrote:
since they are handled one at a time, shouldn't GetAsyncKeyState work for what he's trying to do.
Having never used that function, I do not know.
Unlike the Ctrl, Alt, Windows, and Shift keys, I don't think the keyboard is going to let both the left and down arrows be pressed simultaneously. I've not verified this, however, other than trying it in a text editor. Whichever key happened to get pressed first is the direction in which the cursor moves.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
for a while, I was dabbling in DirectX game programming fundamentals. This was a simple way of making an object move diagonally by pressing a vertical and horizontal arrow key at the same time. I know that it works in that situation, so I think it should work for this one also
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
I wonder if that is specific to DirectInput (which was apparently not an option for the OP), or if it would apply to all of Windows.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Well, I wasn't actually using DirectInput. But this was more a Windows program with the keydown being handled in the message loop. Something like this:
if(GetAsyncKeyState(VK_LEFT)
m_object.left -= .01.
if(GetAsyncKeyState(VK_RIGHT)
m_object.left += .01.
if(GetAsyncKeyState(VK_UP)
m_object.top -= .01.
if(GetAsyncKeyState(VK_DOWN)
m_object.top += .01.
DrawScene();
at any time if you check the GetAsyncKeyState() function (there's also an additional parameter that escapes me right now), any key that is pressed will return true
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
Uniprocessor really has nothing to do with it. Yes, the message is sent one at a time to an application, but the same happens if it's multi-processor. The message the window gets is serialized because the message queue and a single threaded window proc make it that way.
The keyboard interrupt is free to generate another scan code/send the next byte when the the interrupt handler sends the EOI (End Of Interrupt) control. This happens almost immediately after you've read the key scan code from the port.
Then the key is put into the keyboard buffer and sent off to generate the message. While that is going on, the keyboard is still a hardware device that can interrupt a thread's processing (just like anything else) based on it's current IRQL. So, even on a single processor, the next key press could be retrieved and processed all before the application ever gets dispatched the first key.
The only thing the multi-processor could do is if the first processor got caught on a disk I/O and is at high IRQL, the other processor could handle the next keyboard interrupt at the same time.
However, after the Disk I/O was done the keyboard would have gone and done it's turn before the thread was allowed to reschedule to a lower IRQL anyway. The other funny thing is that actually one processor could be delievering the current key while the other one is processing the next, so it actually could make the situation worse since if it was single processor the hardware interrupt would definately interrupt the keystroke delivery while processing the other key. This is a minor detail though, processing a scan code is farily quick.
Pressing multiple keys the keyboard ends up continously generating one of the keys usually, the last one pressed. So a series of keystrokes could be:
(Make Code) UP (Make Code) DOWN (Make Code) DOWN (Make Code) DOWN (Break Code) UP (Break Code) DOWN
So, even though both keys are pressed the second action is continous so depending on how the application handles this it could move the cursor up then continously down because the application doesn't track the UP key's state. The UP key never provided a break code (key unpress) yet.
So, it depends on how the application tracks the keyboard state. There are also special keys, I don't remember if the keyboard itself handles these or it if was solely a process done by the BIOS, but as you know certain keys maintain a "shift" type state, such as Alt, Control and Shift.
It's been a while since I wrote a keyboard filter driver though or messed with the keyboard locations in bios.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
You cannot process those messages at the same time. You can however, simulate the behaviour by using some boolean states of which key is down and which key is up:
bool m_bIsVKLeftDown, m_bIsVKRightDown;
Second, you need to process the WM_KEYDOWN[^] and WM_KEYUP[^] messages:
afx_msg void OnKeyDown(UINT nChar, UINT nRepCount, UINT nFlags)
{
switch( nChar )
{
case VK_LEFT: m_bIsVKLeftDown = true; break;
case VK_RIGHT: m_bIsVKRightDown = true; break;
}
CYourDerivedClass::OnKeyDown(nChar, nRepCount, nFlags);
}
afx_msg void OnKeyUp(UINT nChar, UINT nRepCount, UINT nFlags)
{
switch( nChar )
{
case VK_LEFT: m_bIsVKLeftDown = false; break;
case VK_RIGHT: m_bIsVKRightDown = false; break;
}
CYourDerivedClass::OnKeyUp(nChar, nRepCount, nFlags);
}
After that, you can move your window how you want depending on the different states.
Hope this helps
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
My app needs access to a drive on another system on my network - however, the system may not be powered on and therefore a permanent system mapping will be a problem at boot-up time. How can I set up a network mapping programmatically when my app starts (and premsumably drop that mapping when the app closes) ? Many thanks for help !
Doug
|
|
|
|
|
Try NetUseAdd() or WNetAddConnection2() .
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I would like to attempt to do some X-Y graphing without using MFC. I want to use generic C++ and some graphics libraries and put together a console application. Are there any free graphics libraries? If so, can you do use any simple controls with them?
Jerry
|
|
|
|
|
|
|
Hi guys,
Can any one help me on this. I have a VB DLL and i need to call it in one of C code in VC++. can any one provide me a sample code or suggest me how to do.
Cheers
Tuscan.
|
|
|
|
|
Tuscan wrote:
I have a VB DLL and i need to call it...
Use LoadLibrary() for this.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Presumably this is an 'ActiveX DLL'. Look at the documentation for the #import statement.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi All,
I have a problem.
I have written a Hook Dll. I want to pass a handle from my dll to the application which sets the hook.
So I think I have to use Shared data using
#pragma comment(linker, "/SECTION:.A2IDATA,RWS")
#pragma data_seg (".A2IDATA")
HWND hDlgWnd = NULL;
#pragma data_seg()
Thus I have defined shared section in my dll. But how do I use this shared dta in my application. if write directly
HWND hWnd = hDlgWnd // This give me compile time error saying hDlgWnd not defined..
so how do i access this shared hDlgWnd memory..?
I would appreciate your answer in this regard?
--------------
Vaibhav...
|
|
|
|
|
The data segment of the DLL is not 'visible' to the EXE, even though it is SHARED among all the EXE that have the DLL loaded.
There might be other solutions, but this one is fairly easy and safe to do:
Write a function to return the value of hDlgWnd.
Export the function from the DLL.
Call the function from the EXE instead of trying to access the variable directly from within the EXE.
|
|
|
|
|
Thanks for the answere.
--------------
Vaibhav...
|
|
|
|
|
Hi!
I'm trying to write a small program that analyzes the text in a normal text file.
I'm using the C++ ifstream methods.
My question is:
char *buf;
buf = new char;
ifstream file("test.txt");
...
file.getline(buf, 100);
When I do this buf will contain a row of text.
How do I do to know the size of buf??
I've tried sizeof(buf) but I get = 4
Debugging the code I see that buf has more then 4 character...counting them I get to 77.
Any good tips!
Thanks!
|
|
|
|
|
strlen() function gives the length of a C string, when Sizeof returns the size in bytes of the variable passed as its parameter...
when you write
char *buf;
sizeof(buf);
it will always return 4 because on 32-bits architecture, pointers are 32 bits long, ie. 4 bytes...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
char buf[100];
ifstream file("test.txt");
...
file.getline(buf, 100);
you should do this
I love Programming
|
|
|
|
|
|
Hello,
You can retrieve the extraction count. This is the amount of characters read from the last call to an unformatted input function. Look here[^] and here[^] for more information on gcount() and basic_istream respectively.
int nCount = file.gcount();
Hope this helps.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hachaso wrote:
file.getline(buf, 100);
If you are going to be asking for 100 bytes from the file, the buffer needs to be large enough. As it stands you are only allocating room for 1. Change the allocation to:
buf = new char[100]; Don't forget to delete it when done!
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I am not able to read plain 8-bit text files (like the one created by Notepad) under windows CE, because this OS natively uses 2-byte Unicode characters: it reads one character every two bytes... For example, the text "ciao" may become 2 chinese symbols.
I'm using the MFC, and CFile::Read(), CArchive::ReadString() ... all don't work. How can i tell him to treat text files as 1-byte ASCII files?
Or maybe i can convert the strings to 8-bit AFTER reading them, but this way i couldn't use ReadString; it wouldn't find the ASCII LineFeed while reading.
Thanks
|
|
|
|