Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2022-09

Getting Shift key with PTCCRT

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

James Richters

I have some key sequences with PTCCRT.READKEY where I use a lower case letter to do one thing and an uppercase to do another, but if the Capslock is on, they do the wrong things. Is there a way I can check the condition of the shift key to see if shift was actually pressed instead of just going by whether I got a capital letter or not? The key input is not something that is ever displayed on the screen, it's just making selections and doing them.

James

Reply by email

Unknown author
to James Richters
James Richters wrote 7 lines
I have some key sequences with PTCCRT.READKEY where I use a lower case letter to do one thing and an uppercase to do another, but if the Capslock is on, they do the wrong things. Is there a way I can check the condition of the shift key to see if shift was actually pressed instead of just going by whether I got a capital letter or not? The key input is not something that is ever displayed on the screen, it's just making selections and doing them.

looking at the list of constants in ptcpas, i find PTCKEY_SHIFT... i also find, in Classes, the IPTCKeyEvent which has a GetShift function as well as a Shift property... seems like you should be able to the shift status with something like

type myKeyEvent : IPTCKeyEvent;
type myShiftStatus : boolean;
myShiftStatus := myKeyEvent.Shift;

https://ptcpas.sourceforge.io/api-reference/ptc/iptckeyevent.html

NOTE: it has been way too long since i've actually written any pascal code... take the above with a grain of salt... i may have the syntax all wrong...

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list where it belongs!*

Reply by email

James Richters
to Unknown author

Thanks for the suggestion

I think the syntax should be:
type myKeyEvent = IPTCKeyEvent;
Var myShiftStatus : boolean;
myShiftStatus := myKeyEvent.Shift;

but I get IPTCKeyEvent not found. I wonder if it's only designated as internal.. or if I need to use something other than PTCGraph and PTCCRT

James

looking at the list of constants in ptcpas, i find PTCKEY_SHIFT... i also

find, in Classes, the IPTCKeyEvent which has a GetShift function as well as a Shift

property... seems like you should be able to the shift status with

something like

type myKeyEvent : IPTCKeyEvent; type myShiftStatus : boolean; myShiftStatus := myKeyEvent.Shift;

Reply by email

Unknown author
to James Richters
James Richters wrote 7 lines
Thanks for the suggestion I think the syntax should be: type myKeyEvent = IPTCKeyEvent; Var myShiftStatus : boolean; myShiftStatus := myKeyEvent.Shift;

i told you i probably had the syntax wrong :lol:

but I get IPTCKeyEvent not found. I wonder if it's only designated as internal.. or if I need to use something other than PTCGraph and PTCCRT

you're probably not using the ptc unit directly so you can use it in your code...

i don't like this documentation format without examples but it is what it is...

https://ptcpas.sourceforge.io/api-reference/ptc/index-4.html

also look here in procedure GetKeyEvents...

https://github.com/alrieckert/freepascal/blob/master/packages/graph/src/ptcgraph/ptccrt.pp

if you are already using PTC's keyevents, then you should be able to get the shift status already...

i'm not even going to try writing any code this time... i don't have FPC or even TP/BP installed any more since i stopped writing code for fidonet stuff some years back ;)

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list where it belongs!*

Reply by email

Nikolay Nikolov
to James Richters: Thanks for the suggestion I think the syntax should be: type myKeyEvent = IPTCKeyEvent;…
James Richters wrote 10 lines
Thanks for the suggestion I think the syntax should be: type myKeyEvent = IPTCKeyEvent; Var myShiftStatus : boolean; myShiftStatus := myKeyEvent.Shift; but I get IPTCKeyEvent not found. I wonder if it's only designated as internal.. or if I need to use something other than PTCGraph and PTCCRT

It's internal if you use ptccrt and ptcgraph, but it's available if you use ptc directly. These are two different APIs:

ptc - low level, non-Borland compatible API

ptcgraph, ptccrt, ptcmouse - these use ptc to provide a Borland BGI-compatible and CRT-unit compatible support (plus mouse, which was never supported by Borland, but is nice to have also ;-) ). Recently, I don't have much time to work on ptc (unfortunately), but you can look at the source yourself and write a patch by yourself to get what you need. The conversion of ptc key events to CRT-like key codes happens in ptccrt.pp, procedure GetKeyEvents (lines 113..534). It tries to convert ptc key events to what CRT in dos used to return. There are lots of compatibility factors involved, which results in some key data loss, but you can modify it at your will for your own purposes. Perhaps we can extend ptccrt to be able to return the whole ptc key event as well? It can be done, unfortunately, the Borland ReadKey/KeyPressed API wasn't designed to do that, so new functions appear to be necessary.

Show quoted text 14 lines
James > looking at the list of constants in ptcpas, i find PTCKEY_SHIFT... i also find, in Classes, the IPTCKeyEvent which has a GetShift function as well as a Shift > property... seems like you should be able to the shift status with something like > type myKeyEvent : IPTCKeyEvent; > type myShiftStatus : boolean; > myShiftStatus := myKeyEvent.Shift; _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Tomas Hajny
to Nikolay Nikolov
Nikolay Nikolov wrote 32 lines
On 9/10/22 17:57, James Richters via fpc-pascal wrote: > Thanks for the suggestion > > I think the syntax should be: > type myKeyEvent = IPTCKeyEvent; > Var myShiftStatus : boolean; > > myShiftStatus := myKeyEvent.Shift; > > but I get IPTCKeyEvent not found. I wonder if it's only designated as > internal.. or if I need to use something other than PTCGraph and > PTCCRT It's internal if you use ptccrt and ptcgraph, but it's available if you use ptc directly. These are two different APIs: ptc - low level, non-Borland compatible API ptcgraph, ptccrt, ptcmouse - these use ptc to provide a Borland BGI-compatible and CRT-unit compatible support (plus mouse, which was never supported by Borland, but is nice to have also ;-) ). Recently, I don't have much time to work on ptc (unfortunately), but you can look at the source yourself and write a patch by yourself to get what you need. The conversion of ptc key events to CRT-like key codes happens in ptccrt.pp, procedure GetKeyEvents (lines 113..534). It tries to convert ptc key events to what CRT in dos used to return. There are lots of compatibility factors involved, which results in some key data loss, but you can modify it at your will for your own purposes. Perhaps we can extend ptccrt to be able to return the whole ptc key event as well? It can be done, unfortunately, the Borland ReadKey/KeyPressed API wasn't designed to do that, so new functions appear to be necessary.

Old TP/BP programs were usually accessing the BIOS ShiftState "variable" (using direct BIOS memory access). TV unit Drivers provided this functionality using function GetShiftState (available in FreeVision as well, of course). If you're looking for adding something compatible to TP/BP functionality, ShiftState (e.g. as a property), or GetShiftState function might be good candidates for such an addition, IMHO.

Tomas

Reply by email

James Richters
to Tomas Hajny

I came up with a solution for this. Since I am on windows, I found I can just check GetAsyncKeyState between keypressed and readkey like this:

         If PTCCRT.KeyPressed then
            Begin
	   isShiftDown := GetAsyncKeyState(VK_Shift);
                 MyKey:=PTCCRT.ReadKey;
            End;

James

Reply by email