Computer Science Canada

keyboard keys (help)

Author:  turing91 [ Thu Jan 11, 2007 9:49 pm ]
Post subject:  keyboard keys (help)

How would you make a simple program where if you pressed the "d" key on the keyboard it says something like "You pressed the d key"

i know you can use
code:

var key : string (1)
loop
    getch (key)
    if key = KEY_CTRL_D then
        put "You pressed the 'd' key"
    end if
end loop


but how would you do it without pressing control?

Author:  Ultrahex [ Thu Jan 11, 2007 10:45 pm ]
Post subject:  Re: keyboard keys (help)

There is actually two ways for keyboard input... but i think you understand what you are doing so ill just show you the code(s)

code:

/*
  Same Method in Which You
  Prescribed Above Using CTRL
*/

var key : string (1)
loop
    getch (key)
    if key = 'd' then
        put "You pressed the 'd' key"
    end if
end loop



code:

/*
  This loops repeatedly, and check each loop whether
  the character 'd' is being pressed, and if so, runs code.
*/

var chars : array char of boolean
loop
    Input.KeyDown (chars)
    if chars ('d') then
        put "You pressed the 'd' key"
    end if
    delay(10)
end loop


: