Detecting SHIFT in Virtual Pascal Win32?

I'm currently porting a DOS textmode game to Win32 using Virtual Pascal. I've used the below code to detect whether or not SHIFT is pressed, but it doesn't work when I try to compile in Virtual Pascal. I get "Error 3: Unknown identifier 'registers'".

[CODE]
function SHIFTDOWN : boolean;
var regs : registers;
begin
FillChar (regs, SizeOf(regs), 0);
regs.ah := $02;
Intr ($16, regs);
shiftdown := (regs.al and $02) = $02;
end;
[/CODE]

Any advice on how to detect SHIFT in Virtual Pascal Win32?

Comments

  • [b][red]This message was edited by Alcatiz at 2006-7-8 13:58:6[/red][/b][hr]
    : I'm currently porting a DOS textmode game to Win32 using Virtual Pascal. I've used the below code to detect whether or not SHIFT is pressed, but it doesn't work when I try to compile in Virtual Pascal. I get "Error 3: Unknown identifier 'registers'".
    :
    : [CODE]
    : function SHIFTDOWN : boolean;
    : var regs : registers;
    : begin
    : FillChar (regs, SizeOf(regs), 0);
    : regs.ah := $02;
    : Intr ($16, regs);
    : shiftdown := (regs.al and $02) = $02;
    : end;
    : [/CODE]
    :
    : Any advice on how to detect SHIFT in Virtual Pascal Win32?
    :

    Hi !

    First of all you can include some assembler in a Virtual Pascal source code using the [B]asm[/B] directive.

    If you have a look at the DOS unit in the [B]source
    tl[/B] folder you'll see that some Turbo pascal types (like [B]Registers[/B]), procedures and functions (like [B]Intr[/B]) are not implemented. The reason is that interrupt and direct port handling don't work in protected mode.


  • :
    : Hi !
    :
    : First of all you can include some assembler in a Virtual Pascal source code using the [B]asm[/B] directive.
    :
    : If you have a look at the DOS unit in the [B]source
    tl[/B] folder you'll see that some Turbo pascal types (like [B]Registers[/B]), procedures and functions (like [B]Intr[/B]) are not implemented. The reason is that interrupt and direct port handling don't work in protected mode.
    :
    :

    So, I can't modify the code to make it work in protected mode? Bummer. Do you know of any other way to detect whether or not SHIFT is down in protected mode?
  • : :
    : : Hi !
    : :
    : : First of all you can include some assembler in a Virtual Pascal source code using the [B]asm[/B] directive.
    : :
    : : If you have a look at the DOS unit in the [B]source
    tl[/B] folder you'll see that some Turbo pascal types (like [B]Registers[/B]), procedures and functions (like [B]Intr[/B]) are not implemented. The reason is that interrupt and direct port handling don't work in protected mode.
    : :
    : :
    :
    : So, I can't modify the code to make it work in protected mode? Bummer. Do you know of any other way to detect whether or not SHIFT is down in protected mode?
    :
    To detect if the SHIFT key is pressed you can use the [b]GetKeyboardState[/b] function of then [b]VPUtils[/b] unit as follows :
    [code]if GetKeyboardState( kbd_Shift ) then
    ...[/code]
  • : To detect if the SHIFT key is pressed you can use the [b]GetKeyboardState[/b] function of then [b]VPUtils[/b] unit as follows :
    : [code]if GetKeyboardState( kbd_Shift ) then
    : ...[/code]
    :

    I tried to test this in the below code, but it doesn't seem to work. It always writes "SHIFT NOT PRESSED!".

    [CODE]
    PROGRAM TEST;

    USES Crt, VPUTILS;

    VAR PressedKey : Word;

    BEGIN
    PressedKey := 0;
    ClrScr;
    REPEAT
    REPEAT UNTIL KeyPressed;
    PressedKey := Ord(ReadKey);
    GotoXY(1,1);
    IF GetKeyboardState(kbd_Shift) THEN Write('SHIFT PRESSED! ')
    ELSE Write('SHIFT NOT PRESSED!');
    UNTIL PressedKey = 27;
    END.
    [/CODE]
  • : : To detect if the SHIFT key is pressed you can use the [b]GetKeyboardState[/b] function of then [b]VPUtils[/b] unit as follows :
    : : [code]if GetKeyboardState( kbd_Shift ) then
    : : ...[/code]
    : :
    :
    : I tried to test this in the below code, but it doesn't seem to work. It always writes "SHIFT NOT PRESSED!".
    :
    : [CODE]
    : PROGRAM TEST;
    :
    : USES Crt, VPUTILS;
    :
    : VAR PressedKey : Word;
    :
    : BEGIN
    : PressedKey := 0;
    : ClrScr;
    : REPEAT
    : REPEAT UNTIL KeyPressed;
    : PressedKey := Ord(ReadKey);
    : GotoXY(1,1);
    : IF GetKeyboardState(kbd_Shift) THEN Write('SHIFT PRESSED! ')
    : ELSE Write('SHIFT NOT PRESSED!');
    : UNTIL PressedKey = 27;
    : END.
    : [/CODE]
    :
    Well your code works fine in my Windows 2000 console - but I had to add this compiler directive :
    [code]
    {$PMTYPE VIO}
    [/code]

  • : Well your code works fine in my Windows 2000 console - but I had to add this compiler directive :
    : [code]
    : {$PMTYPE VIO}
    : [/code]
    :


    I tried adding this, but that didn't do anything. I'm running Windows 98 if that something interferes with what I'm trying to do. Also, in the "Linker" options the "Application" is already set to "Compatible with GUI". Isn't that what the {$PMTYPE VIO} does?
  • [b][red]This message was edited by Alcatiz at 2006-7-10 12:22:6[/red][/b][hr]
    : : Well your code works fine in my Windows 2000 console - but I had to add this compiler directive :
    : : [code]
    : : {$PMTYPE VIO}
    : : [/code]
    : :
    :
    :
    : I tried adding this, but that didn't do anything. I'm running Windows 98 if that something interferes with what I'm trying to do. Also, in the "Linker" options the "Application" is already set to "Compatible with GUI". Isn't that what the {$PMTYPE VIO} does?
    :
    Yes it's right.

    I also tried the code on Windows 98 and it doesn't detect the shift key. It seems to work only on Windows NT/2000/XP.
    I think that Windows 98 allows you to read ports directly so maybe you can try to read port 60h in your loop ?


  • : [b][red]This message was edited by Alcatiz at 2006-7-10 12:22:6[/red][/b][hr]
    : : : Well your code works fine in my Windows 2000 console - but I had to add this compiler directive :
    : : : [code]
    : : : {$PMTYPE VIO}
    : : : [/code]
    : : :
    : :
    : :
    : : I tried adding this, but that didn't do anything. I'm running Windows 98 if that something interferes with what I'm trying to do. Also, in the "Linker" options the "Application" is already set to "Compatible with GUI". Isn't that what the {$PMTYPE VIO} does?
    : :
    : Yes it's right.
    :
    : I also tried the code on Windows 98 and it doesn't detect the shift key. It seems to work only on Windows NT/2000/XP.
    : I think that Windows 98 allows you to read ports directly so maybe you can try to read port 60h in your loop ?
    :
    :
    :

    Ok, I'll try that. Thanks for your help! :o)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion