Register and join over 40,000 other developers!
Recent Topics
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
-
Job Gig PHP Form Needed
PJohnson - Apr 18 2019 03:55 AM
-
How to make code run differently depending on the platform it is running on?
xarzu - Apr 05 2019 09:17 AM
-
How do I set a breakpoint in an attached process in visual studio
xarzu - Apr 04 2019 11:47 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

1 reply to this topic
#1
Posted 31 May 2012 - 06:11 AM
Hello!
I'm a beginner in Pascal and I'm working on a small WIngraph game. At some point on the game, the character (which is a block) has to lay down (the block gets half of its original height). I want this to happen while holding the arrow-down key but the way I implemented it is not actually working. Another problem I have is I don't know how to read keys simultaneously (that would be needed when, for example, running to the right and jumping).
That's how I tried to write it:
key:=readkey;
case key of
arrow down code#:repeat
block gets half of its height
main loop of the program (drawing shapes etc)
until keypressed = false; <-- that's the problem. I expected the code to run fine while the key was pressed and as soon as its released, the block should get its normal height and then the program would run based on its main loop, but outside of this procedure.
Everything is working, except that key-holding thing.
Thank you!
I'm a beginner in Pascal and I'm working on a small WIngraph game. At some point on the game, the character (which is a block) has to lay down (the block gets half of its original height). I want this to happen while holding the arrow-down key but the way I implemented it is not actually working. Another problem I have is I don't know how to read keys simultaneously (that would be needed when, for example, running to the right and jumping).
That's how I tried to write it:
key:=readkey;
case key of
arrow down code#:repeat
block gets half of its height
main loop of the program (drawing shapes etc)
until keypressed = false; <-- that's the problem. I expected the code to run fine while the key was pressed and as soon as its released, the block should get its normal height and then the program would run based on its main loop, but outside of this procedure.
Everything is working, except that key-holding thing.
Thank you!
#2
Posted 22 June 2012 - 10:52 PM
Hi Pjp, welcome to CodeCall.
Information about the compiler will be helpful here. Basically you need a timer to simulate repeating keypress. Activate the timer when key is down and deactivate it when the key is up (released). In Delphi it would be something like this:
Event handler for the form's OnKeyDown event.
Event handler for the form's OnKeyUp event.
And event handler for Timer1's OnTimer:
Information about the compiler will be helpful here. Basically you need a timer to simulate repeating keypress. Activate the timer when key is down and deactivate it when the key is up (released). In Delphi it would be something like this:
Event handler for the form's OnKeyDown event.
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin Timer1.Enabled := True; end;
Event handler for the form's OnKeyUp event.
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin Timer1.Enabled := False; end;
And event handler for Timer1's OnTimer:
procedure TForm1.Timer1Timer(Sender: TObject); var vKey: Word; AShift: TShiftState; begin vKey := ... // Get what key is currently pressed vShift := ... // Get which extended keys (Shift, Ctrl, Alt, etc) that also pressed at the time case ... // here do whatever you need to do if the detected keyboard button end; end;
Also tagged with one or more of these keywords: keyboard
Language Forums →
PHP →
Virtual KeyboardStarted by mihosa, 02 Jul 2014 ![]() |
|
![]() |
||
General Forums →
General Computing →
Poll
[POLL] What Keyboard Layout Do You Use?Started by PBJ, 18 Jun 2014 ![]() |
|
![]() |
||
Language Forums →
Visual Basic →
get key pressed out of form?Started by AlaeMrich, 18 Jun 2014 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
[C++/SDL] Key press/release checking trouble.Started by Kylo, 02 Oct 2013 ![]() |
|
![]() |
||
General Forums →
Mobile Development →
XCode iPhone move view away from keyboardStarted by JakeWelton, 18 Jul 2013 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download