| | |
Reading Keystates
![]() |
I can read which key is pressed using getch(). For example i can read whether left arrow is pressed or not. But i want know whether both left arrow and up arrow is pressed at the same time or not-- I want to move an object diagonally across the screen if both LEFT+ UP arrow is pressed and that's why i want to know this thing.
Also how do i know whether a key is pressed or released.
Also while making games i noticed that I dont get smooth movement of the space-craft that i control. Like if I pushed right arrow(and kept it pressed) then it moves one step to right first time but then stops for a while and only then it keeps goin in the right direction as long as I keep the right arrow pressed. The problem here is the lag between the first time it moves and when it keeps goin in a direction. I want to eliminate the lag and thus give a smoother control.
I know all these problems can be solved using DirectInput, but i would like to know if i can do so in CONSOLE,
Thanx
Also how do i know whether a key is pressed or released.
Also while making games i noticed that I dont get smooth movement of the space-craft that i control. Like if I pushed right arrow(and kept it pressed) then it moves one step to right first time but then stops for a while and only then it keeps goin in the right direction as long as I keep the right arrow pressed. The problem here is the lag between the first time it moves and when it keeps goin in a direction. I want to eliminate the lag and thus give a smoother control.
I know all these problems can be solved using DirectInput, but i would like to know if i can do so in CONSOLE,
Thanx
•
•
•
•
Originally Posted by Asif_NSU
well, i have seen the page but i could not find anything useful, there were something about reading function keys but nothing about reading reading multiple keys or different keystates.
void GameLoop()
{
UINT nSeconds = timeGetTime()
//for your object to move every tenth of a second
if((gSeconds + 100) > nSeconds)
{
gSeconds = nSeconds;
if(GetAsyncKeyState(VK_UP))
gTop += 1;
if(GetAsyncKeyState(VK_DOWN))
gTop -= 1;
if(GetAsyncKeyState(VK_LEFT))
gLeft -= 1;
if(GetAsyncKeyState(VK_RIGHT))
gLeft += 1;
}
//do some type of update to your object's drawn position
m_Object.UpdatePosition(gLeft,gTop);
}
Having a function like this is how most games are done, but in the application's message loop, it's only done if the msg is WM_IDLE so that your game only uses idle time to update the game. you won't see any performance hits in your game, and it will allow for other events to transpire. Hope this helps. (this isn't the most efficient algorithm in the world, or the best, but I just put it together :lol: )
•
•
Join Date: May 2004
Posts: 75
Reputation:
Solved Threads: 5
•
•
•
•
Originally Posted by GDFans
You can do this by capturing keybord interrupt.(09h?yes)
I remember I have seen an article solving this problem.Actually,it is not
an easy stuff,but Im not sure I can check it out.:~)
...
•
•
•
•
Originally Posted by GDFans
...
I think I have the same problem with you.Im thinking about reading data
from I/O directly,but I havnt done it yet.
If you really want to play with hardware, the old, 16-bit DOS edition of the The Art of Assembly Language Programming has a chapter on the IBM PC keyboard and int 9 handling which I think is quite useful, if you don't mind x86 assembly.
--sg
![]() |
Similar Threads
- problems with reading random access line from a file (C++)
- reading and printing a file to screen in C (C)
- floppy drive stopped reading disks on HP laptop (Windows NT / 2000 / XP)
Other Threads in the C Forum
- Previous Thread: List View Sorting and Callback
- Next Thread: Source File Too Big
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking hardware highest homework i/o inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h





