Computer Science Canada

Input.KeyDown

Author:  JSBN [ Fri Jun 20, 2003 3:11 pm ]
Post subject:  Input.KeyDown

For Input.KeyDown, how do i detect an uppercase letter (ie. A)
i know to detect shift it is (KEY_SHIFT) and for a it is ('a').
Itried puting the 2 togeather, that d'dn't work, and i tried ('A'), but that didn't work either.
:/

Author:  Tony [ Fri Jun 20, 2003 9:35 pm ]
Post subject: 

you check for both at same time.

if chars(Key_SHIFT) and chars('a') then
...

Author:  JSBN [ Sat Jun 21, 2003 12:05 am ]
Post subject: 

i already tried that :/

Author:  Blade [ Sat Jun 21, 2003 9:16 am ]
Post subject: 

tony is right.... if you go to the help file, then...
Quote:
The array returned is a list of all the characters. A key is currently pressed if the array element with the corresponding character is true. For example, the a key is pressed is chars ('a') is true. Note that each key is individually represented, so if the user has pressed Shift+a to get a 'A', then Input.KeyDown would register Shift and 'a' as pressed, but not 'A'.

and this works for me
code:
var chars : array char of boolean
loop
    Input.KeyDown (chars)
    if chars ('a') & chars (KEY_SHIFT) then
        put "hi"
    else
        put "bye"
    end if
    locate (1, 1)
end loop

Author:  JSBN [ Sun Jun 22, 2003 12:43 pm ]
Post subject: 

ok, i figured out my problem, i had it set up wrong.
i had:
code:
if chars ('a') then
...
elsif chars ('a') and chars (KEY_SHIFT) then
...

what u need is :
code:
if chars ('a') and chars (KEY_SHIFT) then
...
elsif chars ('a') then
...

THe upper case letter MUST go b4 the lowercase letter
THx for your help, and esspecially to blade for makingme relize this.

Author:  JSBN [ Mon Jun 23, 2003 6:23 pm ]
Post subject: 

another question, I was wondering what Caps lock was.

Author:  Homer_simpson [ Mon Jun 23, 2003 6:28 pm ]
Post subject: 

i dont think that input keydown supports capslock =/

Author:  Asok [ Mon Jun 23, 2003 6:40 pm ]
Post subject: 

if ANYONE knows how to detect caps lock via Input.Keydown they'll get 25 bits. (must provide source code)

Author:  Homer_simpson [ Mon Jun 23, 2003 8:08 pm ]
Post subject: 

lol if anyone finds out how to do that using turing... he'll get 100 bits...(knowing that it's impossible...)

Author:  Andy [ Mon Jun 23, 2003 8:23 pm ]
Post subject: 

ya it is impossible... can you even detect if shift is pressed?

Author:  Catalyst [ Mon Jun 23, 2003 8:26 pm ]
Post subject: 

u people...

code:
var chars : array char of boolean
var key : string (1) := "!"
fcn capTest (k : string (1)) : boolean
    if ord (k) >= 65 and ord (k) <= 90 then
        result true
    else
        result false
    end if
end capTest
loop
    getch (key)
    Input.KeyDown (chars)
    if chars (KEY_SHIFT) = false and capTest (key) then
        put "Caps Lock is on"
    elsif chars (KEY_SHIFT) = true and capTest (key)=false then
        put "Caps Lock is on"       
    else
        put "Caps Lock is off"
    end if
end loop

Author:  Andy [ Mon Jun 23, 2003 8:30 pm ]
Post subject: 

catalyst that only checks for letters and we want to know if caplocks is pressed without inputing data.

Author:  JSBN [ Mon Jun 23, 2003 8:32 pm ]
Post subject: 

can u get so that there is no getch?

Author:  Catalyst [ Mon Jun 23, 2003 8:34 pm ]
Post subject: 

i dont think i can do i withour getch since the only reason it works is that getch() picks up on the caps lock

Author:  Asok [ Mon Jun 23, 2003 11:49 pm ]
Post subject: 

JSBN, that should work with what we're doing anyways because var key wont be drawn it just holds the status of caps lock.

Author:  Andy [ Tue Jun 24, 2003 10:33 am ]
Post subject: 

man Input.KeyDown should actually check if a key is pressed down not if a key that can produce a character is pressed down


: