detecting shift (left right up dn pgup pgdn home end) 
Author Message
 detecting shift (left right up dn pgup pgdn home end)

Is it possible to detect
shift left
shift right
shift up
shift dn
shift pgup
shift pgdn
shift home
shift end

e.g. in a texteditor these are used for selecting text.

The keyboard generates an interrupt, so the keystroke can be detected
with keypressed, but the value returned by readkey is the same as for the
keys without the shift.
The same for the FAQ 78 solution for detecting F11 and F12. (BTW. This
procedure lacks a keypressed check)

Of course it is possible to poll the keyboard and look for one of the
shift keys. (see the example program below). But the danger is that the
shift state is missed by the poll if there is a time consuming procedure
in the loop. OTH  I noticed that upon de-pressing the arrow, pgup/dn
home/end key, a shift down key scan is generated again if shift remains
down.

--
Femme

PS The code for checking the keyscan is.

uses crt;
const ch:char=#1;
var   key:byte;
begin
  repeat
    if keypressed then
    begin
      gotoxy(1,1); clreol;
      ch:= readkey;
      if ch=#0 then
      begin write('Extended ');
            ch:=readkey
      end;
      write('Char(',ord(ch),')="',ch,'" ');
    end;
    if port[$60]<>key then
    begin
      gotoxy(1,3); clreol;
      key:=port[$60];
      if (key and $80) = $80
      then write('key(',key and $7f,') up   ')
      else write('key(',key and $7f,') down ')
    end;
  until ch=#27;
end.



Sat, 30 Apr 2005 08:09:34 GMT  
 detecting shift (left right up dn pgup pgdn home end)
Maybe the keyboard status bytes at SEG0040:0000 following (exact
location is in Ralf Browns Intlist)
are something for you, but I doubt it. Otherwise you might need to
programm your own keyboard handler...

Greetings

Markus



Sun, 01 May 2005 02:06:50 GMT  
 detecting shift (left right up dn pgup pgdn home end)

Quote:

> Is it possible to detect
> shift left
> shift right
> shift up
> shift dn
> shift pgup
> shift pgdn
> shift home
> shift end

> e.g. in a texteditor these are used for selecting text.

> The keyboard generates an interrupt, so the keystroke can be detected
> with keypressed, but the value returned by readkey is the same as for the
> keys without the shift.
> The same for the FAQ 78 solution for detecting F11 and F12. (BTW. This
> procedure lacks a keypressed check)

> Of course it is possible to poll the keyboard and look for one of the
> shift keys. (see the example program below). But the danger is that the
> shift state is missed by the poll if there is a time consuming procedure
> in the loop. OTH  I noticed that upon de-pressing the arrow, pgup/dn
> home/end key, a shift down key scan is generated again if shift remains
> down.

> --
> Femme

<snip>

hello. i hope this table will help you:

segment $0040

 17h    BYTE    Keyboard status flags 1:
                    bit 7 =1 INSert active
                    bit 6 =1 Caps Lock active
                    bit 5 =1 Num Lock active
                    bit 4 =1 Scroll Lock active
                    bit 3 =1 either Alt pressed
                    bit 2 =1 either Ctrl pressed
                    bit 1 =1 Left Shift pressed
                    bit 0 =1 Right Shift pressed
 18h    BYTE    Keyboard status flags 2:
                    bit 7 =1 INSert pressed
                    bit 6 =1 Caps Lock pressed
                    bit 5 =1 Num Lock pressed
                    bit 4 =1 Scroll Lock pressed
                    bit 3 =1 Pause state active
                    bit 2 =1 Sys Req pressed
                    bit 1 =1 Left Alt pressed
                    bit 0 =1 Left Ctrl pressed

i've tested this before posting, it worked for me.

you can read the keyboard status flags using mem[$0040:$0017] and
mem[$0040:$0018] in tp6+. then you will have to check for what values
do you need.
example. you need to check if left shift is pressed

var a : byte;

(* check point *)
a := mem [$0040:$0017];

if (a and $02) <> 0 then begin
(* left shift is pressed *)
end;

this is a simple example, maybe not that syntax right for Pascal, but
easy to understand.

greetings
Vasko

ps - the table is copyed form the file 'memory.lst' by Robin Walker.



Sun, 01 May 2005 15:31:33 GMT  
 detecting shift (left right up dn pgup pgdn home end)

Quote:
> <snip>

> hello. i hope this table will help you:

> segment $0040

>  17h BYTE Keyboard status flags 1:
>     bit 7 =1 INSert active
>     bit 6 =1 Caps Lock active
>     bit 5 =1 Num Lock active
>     bit 4 =1 Scroll Lock active
>     bit 3 =1 either Alt pressed
>     bit 2 =1 either Ctrl pressed
>     bit 1 =1 Left Shift pressed
>     bit 0 =1 Right Shift pressed
>  18h BYTE Keyboard status flags 2:
>     bit 7 =1 INSert pressed
>     bit 6 =1 Caps Lock pressed
>     bit 5 =1 Num Lock pressed
>     bit 4 =1 Scroll Lock pressed
>     bit 3 =1 Pause state active
>     bit 2 =1 Sys Req pressed
>     bit 1 =1 Left Alt pressed
>     bit 0 =1 Left Ctrl pressed

> i've tested this before posting, it worked for me.

> you can read the keyboard status flags using mem[$0040:$0017] and
> mem[$0040:$0018] in tp6+. then you will have to check for what values
> do you need.
> example. you need to check if left shift is pressed

> var a : byte;

> (* check point *)
> a := mem [$0040:$0017];

> if (a and $02) <> 0 then begin
> (* left shift is pressed *)
> end;

> this is a simple example, maybe not that syntax right for pascal, but
> easy to understand.

> greetings
> Vasko

> ps - the table is copyed form the file 'memory.lst' by Robin Walker.

Yes, this is exactly what I was looking for. Thanks for finding it Vasko.

I made a few changes  in order to make it work for protected mode. (while
keeping backward compatibility)

{$ifndef ver70}
const seg0040=$0040;
{$endif}
.....
      if (mem[seg0040:$0017] and $3)<>0 then write(' shift');
      if (mem[seg0040:$0017] and $4)<>0 then write(' ctrl');
      if (mem[seg0040:$0017] and $8)<>0 then write(' alt');

--
Femme



Sun, 01 May 2005 17:17:38 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Right Shift

2. language right to left problems

3. Report with data flow from left to right

4. UP - DOWN - LEFT - RIGHT (HELP)

5. $B+ evaluates RIGHT to LEFT?

6. + evaluates RIGHT to LEFT?

7. + evaluates RIGHT to LEFT

8. Report with data flow from left to right

9. Needed: Component to handle currencies while digits appear right-to-left

10. LEFT JOIN: Wrong results when left table is empty

11. Need Program like NC or DN

12. pgup, pgdwn

 

 
Powered by phpBB® Forum Software