Hello!!!
;-))
I have TWO questions:
-first is there a function that can give me back when reading a key its programmation name ( KEY_COMMA , KEY_SEMICOLON2, ....) ? I will experience new beautifull keyboards like turkish and arabic and I would like two know wich code in full plain text the key get back.
-second question
i have a discussion with physical hardware. This hardware is a physical fader wich returns a value from 100 to 0 ( lRetFaderPreset), depending of its position. I m using it like this:
BufferSaisie[prepman]=(int)(fValManuelAtBeg[prepman]+ (lRetFaderPreset * ((fValManuelAtEnd[prepman]-fValManuelAtBeg[prepman])/100)));
So in fact, my function there is working in only one way, from 100 to 0. It means to work I need to get back my faders up to do the next move.
I want to use my fader up to down and down to up , reverting values.
I do not figure how to use is transforming 0 to 100 and 100 to 0 easely, to permit to use it in the two ways, reverting its values.
I m sure that there must be something more elegant than translating thruth an array the value of lRetFaderPreset.
Have you got any idea 
thanks for the answer!
christoph
1. scancode_to_name
2. I have no idea what you are talking about.
Thanks first for your answer about scancode, I will use it !!!

edit:
if (keypressed()) { char const *keyname = scancode_to_name(scancode); textprintf_ex(buffer,font, 80, 230,makecol(100,0,255),-1,"You pressed the %s key.", keyname); }
returns none as string... 
ok, I will try to be more explicit and clear ( wich is quite a thing ...)
i have a real slider connected to my soft
It returns values only in this way:
-100
-90
-80
-70
-60
-50
-40
-30
-20
-10
-0
I m searching how I can program, when my slider is down , an inversion of the values.
Actually , I m obliged to get up my faders.
To be more explicit, it affect the value of BufferSaisie[] thruth a crossfading of levels: from a Value at Begin TO the next value wich is at End.
BufferSaisie[10]=30 at Begin
after crossfade thruth the fader it should arrive at BufferSaisie[10]=95
I m using a physical hardware ( slider, fader, dont know the name) to do it
you can see photo of it there:
http://karistouf.free.fr
Why not just 100 - return value? If it were at 100 when you want 0, 100-100 = 0. If it were at 0 and you want 100, 100-0 = 100. I'm not sure exactly what you are after, but this is the closest thing I can make out to what you want.
hum... because in fact I have TWO faders ....
I wanted to make it more simpler in my explanation
So I m using two fader, one that is manipulating the values at begin, the other the value at end.
When BeginFader is at 0 and EndFader is at 100 my crossfade is done. Begin has a new value ( the before named End)....
I have edited the post on the scan code...
do not understand why it doesn t return anything
OK DEFINITEVELY SCANCODE RETURNS NONE.... must be a dummy thing....
| 1 | |
| 2 | while (index_quit==0) |
| 3 | { |
| 4 | //clear_bitmap(buffer); |
| 5 | |
| 6 | rectfill(buffer,0,0,440,400,makecol(255,255,255)); |
| 7 | draw_sprite(buffer,fond1,(int)-5,0); |
| 8 | |
| 9 | |
| 10 | textprintf_ex(buffer,font, 10, 195,makecol(100,0,255),-1,"Keyboard Detection:"); |
| 11 | |
| 12 | |
| 13 | char const *keyname = scancode_to_name(scancode); |
| 14 | |
| 15 | |
| 16 | textprintf_ex(buffer,font, 80, 230,makecol(100,0,255),-1,"You pressed the %s key.", keyname); |
| 17 | blit(buffer,screen,0,0,0,0,442,442); |
| 18 | |
| 19 | |
| 20 | |
| 21 | rect(buffer, 40,230,50,240,makecol(100,0,255)); |
| 22 | rect(buffer, 40,250,50,260,makecol(100,0,255)); |
| 23 | rect(buffer, 40,270,50,280,makecol(100,0,255)); |
| 24 | rect(buffer, 40,290,50,300,makecol(100,0,255)); |
| 25 | rect(buffer, 40,310,50,320,makecol(100,0,255)); |
| 26 | |
| 27 | |
| 28 | // OK CANCEL BUTTONS |
| 29 | textprintf_ex(buffer,font, 80, 370,makecol(100,0,255),-1,"FORGET! DO IT !"); |
| 30 | rect(buffer, 150,370,160,380,makecol(100,0,255)); |
| 31 | rect(buffer, 320,370,330,380,makecol(100,0,255)); |
| 32 | |
| 33 | if (mouse_y>370 && mouse_y<380) |
| 34 | { |
| 35 | if (mouse_x > 150 && mouse_x<160)//escape |
| 36 | {rectfill(buffer, 151,371,159,379,makecol(0,0,0)); |
| 37 | if (mouse_b&1){index_quit=1;} |
| 38 | } |
| 39 | if (mouse_x>320 && mouse_x<330) |
| 40 | {rectfill(buffer, 321,371,329,379,makecol(0,0,0)); |
| 41 | if (mouse_b&1) |
| 42 | { |
| 43 | index_quit=1;} |
| 44 | } |
| 45 | |
| 46 | |
| 47 | |
| 48 | } |
if (keypressed()) { char const *keyname = scancode_to_name(scancode); textprintf_ex(buffer,font, 80, 230,makecol(100,0,255),-1,"You pressed the %s key.", keyname); }
What is in the scancode value?
keyname string is <none> scancode is O
I made several try, thinking about a trouble with keypress or buffer satured because of the loop while....:'(
Is keyboard installed ? And timer ?
Show us your init routine.
It should look like this:
allegro_init(); install_timer(); install_keyboard(); install_mouse();
yep...
I m under Dev_cpp 4.9.9.2 and with the dev pack of allegro 4.2 from dev pack repository
| 1 | |
| 2 | #include "allegro.h" |
| 3 | #include "stdio.h" |
| 4 | #include "winalleg.h" |
| 5 | |
| 6 | int scancode=0; |
| 7 | BITMAP* buffer; |
| 8 | BITMAP* fond1; |
| 9 | BITMAP* mouse; |
| 10 | bool index_quit=0; |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | int quit_funct() |
| 16 | { |
| 17 | destroy_bitmap(buffer); |
| 18 | destroy_bitmap(fond1); |
| 19 | destroy_bitmap(mouse); |
| 20 | return(0); |
| 21 | } |
| 22 | |
| 23 | //////////////////////////////////////////////////////////////////////////////// |
| 24 | int main() |
| 25 | { |
| 26 | allegro_init(); |
| 27 | |
| 28 | |
| 29 | install_keyboard(); |
| 30 | install_mouse(); |
| 31 | install_timer(); |
| 32 | set_color_depth(16); |
| 33 | set_gfx_mode(GFX_AUTODETECT_WINDOWED,442,442,0,0); |
| 34 | |
| 35 | |
| 36 | |
| 37 | if(set_gfx_mode(GFX_AUTODETECT_WINDOWED,440,400,0,0)!=0){ |
| 38 | set_gfx_mode(GFX_TEXT,0,0,0,0); |
| 39 | allegro_message("%s\nSchwartz_Peter's Video Mode:\n 440,400,0,0 and Higher\n16 or 32 bits better look\n\n", allegro_error); |
| 40 | quit_funct();return 1; |
| 41 | } |
| 42 | fond1=load_bitmap("/schwartzpeter/img/keyboard_detect_flag.tga",NULL); |
| 43 | mouse=load_bitmap("/schwartzpeter/img/curseur1.bmp",NULL); |
| 44 | buffer=create_bitmap(SCREEN_W,SCREEN_H); |
| 45 | |
| 46 | |
| 47 | blit(buffer,screen,0,0,0,0,442,442); |
| 48 | |
| 49 | |
| 50 | |
| 51 | while (index_quit==0) |
| 52 | { |
| 53 | //clear_bitmap(buffer); |
| 54 | |
| 55 | rectfill(buffer,0,0,440,400,makecol(255,255,255)); |
| 56 | draw_sprite(buffer,fond1,(int)-5,0); |
| 57 | |
| 58 | |
| 59 | textprintf_ex(buffer,font, 10, 195,makecol(100,0,255),-1,"Keyboard Detection:"); |
| 60 | |
| 61 | |
| 62 | char const *keyname = scancode_to_name(scancode); |
| 63 | |
| 64 | |
| 65 | textprintf_ex(buffer,font, 80, 230,makecol(100,0,255),-1,"You pressed the %s key. %d", keyname, scancode); |
| 66 | blit(buffer,screen,0,0,0,0,442,442); |
| 67 | |
| 68 | |
| 69 | |
| 70 | rect(buffer, 40,230,50,240,makecol(100,0,255)); |
| 71 | rect(buffer, 40,250,50,260,makecol(100,0,255)); |
| 72 | rect(buffer, 40,270,50,280,makecol(100,0,255)); |
| 73 | rect(buffer, 40,290,50,300,makecol(100,0,255)); |
| 74 | rect(buffer, 40,310,50,320,makecol(100,0,255)); |
| 75 | |
| 76 | |
| 77 | // OK CANCEL BUTTONS |
| 78 | textprintf_ex(buffer,font, 80, 370,makecol(100,0,255),-1,"FORGET! DO IT !"); |
| 79 | rect(buffer, 150,370,160,380,makecol(100,0,255)); |
| 80 | rect(buffer, 320,370,330,380,makecol(100,0,255)); |
| 81 | |
| 82 | if (mouse_y>370 && mouse_y<380) |
| 83 | { |
| 84 | if (mouse_x > 150 && mouse_x<160)//escape |
| 85 | {rectfill(buffer, 151,371,159,379,makecol(0,0,0)); |
| 86 | if (mouse_b&1){index_quit=1;} |
| 87 | } |
| 88 | if (mouse_x>320 && mouse_x<330) |
| 89 | {rectfill(buffer, 321,371,329,379,makecol(0,0,0)); |
| 90 | if (mouse_b&1) |
| 91 | { |
| 92 | index_quit=1;} |
| 93 | } |
| 94 | |
| 95 | |
| 96 | |
| 97 | } |
| 98 | |
| 99 | |
| 100 | |
| 101 | draw_sprite(buffer,mouse,(int)mouse_x,mouse_y); |
| 102 | blit(buffer,screen,0,0,0,0,442,442); |
| 103 | |
| 104 | } |
| 105 | |
| 106 | destroy_bitmap(fond1); |
| 107 | destroy_bitmap(mouse); |
| 108 | remove_timer(); |
| 109 | allegro_exit(); |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | END_OF_MAIN(); |
Well of course it's none. 0 isn't a valid scancode! Try putting in an actual key value, like KEY_ENTER.
wait wait wait....
if i well understand, scancode_funct is not a listening of keyboard but just a converting function ?
Have you really look at exkeys ? If not you should.
no exkeys in dev pack... I will take a look. I was used to a version of allegro about 3 years ago. and characters are not at all my speciality...
when using readkey function it crashes....
int ch; // I get out scancode int .... if(keypressed()) { ch=readkey();} char const *keyname = scancode_to_name(ch); textprintf_ex(buffer,font, 80, 230,makecol(100,0,255),-1,"You pressed the %s key. %d", keyname, ch); blit(buffer,screen,0,0,0,0,442,442);
Yeah, readkey returns a value and scancode combined.
readkeyYou need to read that and find how to get a scancode from readkey.
thanks a lot.
I have read exkeys wich is quite hudge.>:( and full of different ways to do it.
so in fact not very simple to understand how you use this function clearely, simply.
The main thing I know, is that using ch=readkey makes a trash....
wich begins to be quiet ridiculous and tiring for such a little exe to know what is the name of the key ( argghhh)
Yes , I know, the following things must be ridiculous...;D
All of that just to be helpfull to other keyboard and make adaptation quickly...
So it would be very nice if you explain to me what is my error there, and why it crashes ?
I never arrived to crash with allegro before... except when missing media.
waouaouwouaou...:-[
if(keypressed()) { ch=readkey(); //ch is an integer if (ch >> 8) //if ch is not a double key press { //asking to convert ch with scancode in the name of the key we put inside the string keyname char const *keyname = scancode_to_name(ch); textprintf_ex(buffer,font, 80, 230,makecol(100,0,255),-1,"You pressed the %s key. %d", keyname, ch); blit(buffer,screen,0,0,0,0,442,442); } }
No, it's not a double keypress. It gives you two types of information. One is the key value, stored in the first 8 bits of the returned value. The next is the scancode, suck as KEY_ENTER, etc. Both will always be in the value. Therefore, to get the scancode from the value, you take the value of readkey() and do the >> 8, then pass that shifted value to scancode_to_name.
great, Ryan.
This IS an answer. its very clear
so
char const *key = scancode_to_name(ch>>8);
works!
thanks about your answer, because it is far more clear to know that readkey() returns 2 type of informations.
merci