|
-
Sep 18th, 2002, 04:38 PM
#1
Thread Starter
Frenzied Member
not working in win 98?
for some reason this works on xp but not on the schools 98 machines...any idea why?
Code:
#include <iostream.h>
#include <windows.h>
int GetKey();
int main()
{
int test;
while(1)
{
test = GetKey();
if(test!=256)
cout<<test<<endl;
}
return 0;
}
int GetKey()
{
int num = 0;
for(int i=0; i<256; i++)
{
num = GetAsyncKeyState(i);
if(num!=0)
{
return i;
}
}
}
it says when the mouse is being clicked, but nothign works for the keyboard
-
Sep 18th, 2002, 05:00 PM
#2
Win98 sucks, but so does WinXP...
I can't help you on that, but use <iostream> anyway...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 19th, 2002, 07:14 PM
#3
Thread Starter
Frenzied Member
from msdn:
Code:
Return Value
If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. However, you should not rely on this last behavior; for more information, see the Remarks.
Windows NT/2000/XP: The return value is zero for the following cases:
The current desktop is not the active desktop
The foreground thread belongs to another process and the desktop does not allow the hook or the journal record.
Windows 95/98/Me: The return value is the global asynchronous key state for each virtual key. The system does not check which thread has the keyboard focus.
Windows 95/98/Me: Windows 95 does not support the left- and right-distinguishing constants. If you call GetAsyncKeyState with these constants, the return value is zero.
I don't really understand if thats a problem but does that mean it will work differently in 98?
-
Sep 19th, 2002, 09:05 PM
#4
Frenzied Member
-
Sep 20th, 2002, 02:00 AM
#5
GetKeyState is only for use within message handlers.
Use DirectInput
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 20th, 2002, 03:02 PM
#6
Thread Starter
Frenzied Member
don't have directx on the school computers 
how about GetKeyboardState()? that seems like it will work...but whenever I try it I get a conversion error...haven't been able to fix it
-
Sep 20th, 2002, 03:25 PM
#7
Frenzied Member
Originally posted by CornedBee
GetKeyState is only for use within message handlers.
Use DirectInput
DI is even worse... then you actually have to process the keyboard state =).
Z.
-
Sep 21st, 2002, 05:12 AM
#8
At least it represents the REAL state of the keyboard...
GetKeyboardState should work. It expects an array of chars to be passed!
GetKeyState returns the state of a key at the time of the last message - which is a little bit tricky in a console app.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 21st, 2002, 07:07 AM
#9
Thread Starter
Frenzied Member
I tried that but I get this error
cannot convert parameter 1 from 'char (*)[256]' to 'unsigned char *'
char ks[256];
while(1)
{
GetKeyboardState(&ks);
for(int i=0; i<257; i++)
{
cout<<ks[i];
}
}
-
Sep 21st, 2002, 01:20 PM
#10
Ya ya Baby!!!Me is Back
-
Sep 21st, 2002, 02:06 PM
#11
Thread Starter
Frenzied Member
cannot convert parameter 1 from 'char [256]' to 'unsigned char *'
-
Sep 21st, 2002, 02:10 PM
#12
Monday Morning Lunatic
Code:
for(int i=0; i<257; i++)
...should be 256 
Try using unsigned char for the array then.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 21st, 2002, 02:38 PM
#13
Thread Starter
Frenzied Member
could have sworn I already tried that
runs fine...but the outputs a little odd
Code:
unsigned char ks[256];
for(int i=0;i<256; i++)
ks[i] = NULL;
while(1)
{
GetKeyboardState(ks);
for(i=0; i<256; i++)
cout<<ks[i];
cout<<endl<<endl;
Sleep(1000);
}
-
Sep 21st, 2002, 03:57 PM
#14
Ya ya Baby!!!Me is Back
I cannot test it cause I got 2 errors from the winuse.h
-
Sep 21st, 2002, 04:04 PM
#15
Thread Starter
Frenzied Member
-
Sep 21st, 2002, 04:09 PM
#16
Thread Starter
Frenzied Member
Code:
#include <iostream.h>
#include <windows.h>
int main()
{
unsigned char ks[256];
for(int i=0;i<256; i++)
ks[i] = NULL;
while(1)
{
GetKeyboardState(ks);
for(i=0; i<256; i++)
cout<<ks[i];
cout<<endl<<endl;
Sleep(1000);
}
return 0;
}
-
Sep 21st, 2002, 04:11 PM
#17
Ya ya Baby!!!Me is Back
That code compile but it not usefull cause it print only happy face
Code:
#include <iostream.h>
#include <windows.h>
void main()
{
unsigned char *ks = new unsigned char[255];
while(true)
{
for (int i = 0 ; i < 255 ; i++)
{
if(GetKeyboardState(ks) !=0)
cout << (unsigned char)ks[i];
else
cout << "Error : Function GetKeyboardState fail\n";
}//Fin du for : i
}//End while
}//Fin du main
-
Sep 21st, 2002, 05:16 PM
#18
Frenzied Member
Gotta read the function specs in the MSDN, guys =):
When the function returns, each member of the array pointed to by the lpKeyState parameter contains status data for a virtual key. If the high-order bit is 1, the key is down; otherwise, it is up. If the low-order bit is 1, the key is toggled. A key, such as the caps lock key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.
Z.
-
Sep 21st, 2002, 05:48 PM
#19
Thread Starter
Frenzied Member
so like this???
Code:
#include <iostream.h>
#include <windows.h>
int main()
{
unsigned char ks[256];
for(int i=0;i<256; i++)
ks[i] = NULL;
while(1)
{
GetKeyboardState(ks);
for(i=0; i<256; i++)
{
if(HIWORD(ks[i])==1)
cout<<i<<" ";
}
cout<<endl<<endl;
}
return 0;
}
-
Sep 21st, 2002, 05:58 PM
#20
Frenzied Member
-
Sep 21st, 2002, 06:22 PM
#21
Thread Starter
Frenzied Member
doesn't seem to really be working for me:
Code:
#include <iostream.h>
#include <windows.h>
int main()
{
unsigned char ks[256];
for(int i=0;i<256; i++)
ks[i] = NULL;
while(1)
{
GetKeyboardState(ks);
for(i=0; i<256; i++)
{
if((ks[i]>>7)==1)
cout<<i<<" ";
}
cout<<endl<<endl;
}
return 0;
}
-
Sep 23rd, 2002, 03:24 AM
#22
instead of
(ar[i] >> 7) == 1
try
(ar[i] & 0x80) != 0
where is the problem with your current code?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 23rd, 2002, 06:14 AM
#23
Thread Starter
Frenzied Member
I just can't get my program to output what keys im pressing...
Code:
#include <iostream.h>
#include <windows.h>
int main()
{
unsigned char ks[256];
bool test = true;
while(test == true)
{
GetKeyboardState(ks);
for(int i=0; i<256; i++)
{
if((ks[i] & 0x80) != 0)
{
cout<<i<<" ";
test = false;
}
}
}
return 0;
}
this doesn't seem to be working either it just doesn't register anything in the if statement this way
Last edited by SteveCRM; Sep 23rd, 2002 at 06:17 AM.
-
Sep 23rd, 2002, 06:49 AM
#24
Frenzied Member
This is annoying... Id like to put it down to this being a console application. I use almost exactly the same code for processing my DInput keyboard buffer, and it works like a charm.
Z.
-
Sep 24th, 2002, 05:07 AM
#25
That could be true, maybe the console swallows the keys or something...
Use <iostream>, not <iostream.h>
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|