|
|
| key[KEY_SPACE] backwards |
|
Aqua Regia
Member #9,855
June 2008
|
Is there some sort of function that pushes eg. space instead of checking if it's pushed? |
|
Anomie
Member #9,403
January 2008
|
What do you need an automatically pressed space-bar for? I can't imagine why that'd be necessary... ______________ |
|
Aqua Regia
Member #9,855
June 2008
|
Not only space. I couldn't find a decent key binding program, so I decided to create one myself. Example: if(key[KEY_A]) |
|
Anomie
Member #9,403
January 2008
|
I still...don't really understand why you don't just check for space-bar being pressed... I assume after that you'd have something checking to see if space-bar was 'pressed', to accomplish something? As in: if(key[KEY_A]) space_pressed = true; if(space_pressed == true) runMyFunction(); What's wrong with if(key[KEY_SPACE])? Is there some reason you're checking for an artificial space-bar press, rather than just using a bool or something similar? ______________ |
|
Aqua Regia
Member #9,855
June 2008
|
I never press space myself, but I want it to be pressed when I press A. In your example, space is just a name, it has nothing to do with the spacebar. |
|
Anomie
Member #9,403
January 2008
|
...why? Is there some part of your code that demands that the space-bar be pressed? If so, just change it to A. Or you could have it check to see if A or space-bar were pressed. [edit] Exactly. The keyboard is a human interface device. If you want it to change without human input, you might as well just use a bool instead. [edit2]Wait wait wait, are you going for a 'user defines their own buttons to press for certain things' kinda thing? ______________ |
|
Aqua Regia
Member #9,855
June 2008
|
I just want to be able to bind the keys. |
|
Anomie
Member #9,403
January 2008
|
Alright, yeah... That makes more sense. What you really want to do is to have a variable for each thing you'd like your buttons to do. (probably not the best way, I've never tried this before...) But...something like: Actually, now that I think about it, key[] might not like ints... But you get the idea, anyways. [edit] Just found this in TFM, though, if that's what you really want to do. ______________ |
|
Aqua Regia
Member #9,855
June 2008
|
Something like that I'm looking for yes, but I don't seem to get it working: if(key[KEY_A]) if(key[KEY_SPACE]) I want it to use the floodfill function when you press A. |
|
Anomie
Member #9,403
January 2008
|
Do you have a main loop, checking for input, blitting the buffer to the screen and all that fun stuff? ______________ |
|
Aqua Regia
Member #9,855
June 2008
|
Yeah, and when I press space myself it works like it should. |
|
CGamesPlay
Member #2,559
July 2002
|
No, what Anomie is saying is that you should have it work like this:
-- Ryan Patterson - <http://cgamesplay.com/> |
|
Anomie
Member #9,403
January 2008
|
I dunno why it wouldn't work with key[]...but try using the if (readkey() == (KEY_SPACE); method from the example on that page. [edit] And...yeah... That way is definitely much more useful if you ever plan to do anything more complicated than what you're doing now. Up to you though. ______________ |
|
Aqua Regia
Member #9,855
June 2008
|
What does the "int key_that_you_press_to_make_the_buffer_gray = KEY_A;" do? |
|
Anomie
Member #9,403
January 2008
|
It does this. Very important. ______________ |
|
Thomas Fjellstrom
Member #476
June 2000
|
somewhat important to explicitly note, simulate_keypress only places a new key in allegro's readkey buffer, and does nothing else. -- |
|
CGamesPlay
Member #2,559
July 2002
|
Quote: I dunno why it wouldn't work with key[]...but try using the if (readkey() == (KEY_SPACE); method from the example on that page. Important to note it that simulate_keypress only works on the readkey buffer as Thomas just said, and the snippet you just suggested is not what the page said to do and won't work. To learn how to use readkey, see its manual page. Quote: What does the "int key_that_you_press_to_make_the_buffer_gray = KEY_A;" do? It makes a variable. You can name it whatever you want, but it stores the name of the key that you want to read. When you go to check the key, instead of using a fixed name, you use the name that you stored in the variable. But you are going to have to learn how to use variables to really understand what's going on. -- Ryan Patterson - <http://cgamesplay.com/> |
|
Onewing
Member #6,152
August 2005
|
Here's a primitive mapping system I used in projects a while back. allegro_input.h
allegro_input.cpp
And then, I'd have a place where I'd make the connections: game.cpp
I stopped using it because it needs some cleaning up, but the functionality of it seemed to work fine if I remember correctly. ------------ |
|
Audric
Member #907
January 2001
|
Aqua Regia : It may not be clear so far, but all the KEY_ symbols correspond a number: KEY_A is 1, KEY_SPACE is 75. Since these are simply numbers, you can store them in integer variables, as used in the above explanations. |
|
amber
Member #6,783
January 2006
|
key[KEY_SPACE] = 1 This'll do exactly what you say you want, but probably not what you really want. |
|
CGamesPlay
Member #2,559
July 2002
|
Also it will randomly not work but only sometimes. Doing that is just a bad idea, because Allegro automatically updates that variable from a different thread. -- Ryan Patterson - <http://cgamesplay.com/> |
|
|