MattyGibbard Posted March 13, 2009 Share Posted March 13, 2009 Hi there. I am making a game at the moment, which is turning out pretty well. I'm going along nicely untill I hit a problem. I found that if the player holds down the arrow key, he moves really fast. I was single press movement. At the moment, I'm using a function. Is there a UDF or a function that checks to see if a key has been held down for x ammount of time? Thank you for your time. Link to comment Share on other sites More sharing options...
KaFu Posted March 13, 2009 Share Posted March 13, 2009 #include <Misc.au3> $dll = DllOpen("user32.dll") While 1 Sleep(0) If _IsPressed("28", $dll) Then; Arrow Down $timer = TimerInit() while _IsPressed("28", $dll) sleep(0) WEnd ConsoleWrite("Arrow Down held for " & TimerDiff($timer) & " ms" & @crlf) EndIf If _IsPressed("1B", $dll) Then; ESC MsgBox(0,"_IsPressed", "ESC Key Pressed") ExitLoop EndIf WEnd DllClose($dll) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
MattyGibbard Posted March 13, 2009 Author Share Posted March 13, 2009 Cheers KaFu, that worked fine. Thanks for your time. Link to comment Share on other sites More sharing options...
Authenticity Posted March 13, 2009 Share Posted March 13, 2009 _IsPressed only check to see if this key is currently down and not the least significant bit that tells if the key was pressed since the last call to GetAsyncKeyState. You can modify _IsPressed to do that for you or better write your own function to test for both and return, say, 2 if it was pressed previously or 1 if it's pressed or 0 otherwise. Link to comment Share on other sites More sharing options...
MattyGibbard Posted March 13, 2009 Author Share Posted March 13, 2009 _IsPressed only check to see if this key is currently down and not the least significant bit that tells if the key was pressed since the last call to GetAsyncKeyState. You can modify _IsPressed to do that for you or better write your own function to test for both and return, say, 2 if it was pressed previously or 1 if it's pressed or 0 otherwise.KaFu's script does work, but it pauses the players movement. It's exactly what I wanted, but I still want the player movement. Possibly using an AdLibEnable, I may be able to run the movement at the same time. I'll let you know how I did it once I have finally worked it out. Also, expect the source for my game up soon. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now