![]() |
Trouble with KeyDown - Printable Version +- Mirage Engine (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: General (https://mirage-engine.uk/forums/forumdisplay.php?fid=17) +---- Thread: Trouble with KeyDown (/showthread.php?tid=858) |
Trouble with KeyDown - Stomach Pulser - 05-04-2007 For some reason, my computer doesn't recognize user input when I am blitting...Any suggestions(detailed stuff is below)... First off, this involves 2 projects. The first project has a form with 4 lines drawn on it. It also has a Label. The code for it is this Code: Private Sub Block() The next project involves Blitting. I have 2 pic boxes. One has a 32 x 32 image in it of a sprite. I blit this onto the other picbox and try to get input from the user. Using almost the exact same code as before, I try to get key input. But, it doesn't work at all... The project also has a timer on it. Code: Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long - Spodi - 05-04-2007 Did you make sure KeyPreview is set to = true? - Stomach Pulser - 05-04-2007 ...wow. I never knew that that existed. Problem fixed. Thanks Spodi. Also, is there a more efficient way to check user input from arrow keys?(other than key down or up) - Spodi - 05-04-2007 GetAsyncKeyState + GetActiveWindow is my current favorite. Code: Public Declare Function GetKeyState Lib "User32" (ByVal nVirtKey As Long) As Integer GetKeyState returns non-zero if the key has been pressed, ie: Code: If GetAsyncKeyState(vbKeyLeft) Then Msgbox ":)" else msgbox ":(" GetActiveWindow returns 0 if the current window is not selected. So you can add this to the above example before it: Code: If GetActiveWindow = 0 Then Exit Sub Then you only get keypresses from when your project is active. Not sure how it works with multiple forms, but it works in MDI forms, I know that much. I'm pretty sure it'll work fine, though. :wink: You have to use this with a timer of some sort since you have to constantly check for the key presses, they're not event based like the KeyDown and KeyPress events on the form. - Stomach Pulser - 05-04-2007 Thanks Spodi! I am trying to learn some basics before I do anything and this helps alot! - Spodi - 05-04-2007 Not a problem. 8) - Braydok - 05-04-2007 This'll help me too, thanks! (Hiys Stomach Pulser, lots of people are on here. ![]() ~Braydok/Elec0 - Spodi - 05-04-2007 Wewt, two for the price of one! :lol: |