PDA

View Full Version : Problem with Event.Key.KeySym.Mod



Christian Knudsen
20-04-2008, 02:29 PM
I'm trying to use Event.Key.KeySym.Mod to check if SHIFT has been pressed/released, but I'm getting an error when trying to compile, as the Free Pascal compiler doesn't like '.Mod'. I'm guessing that's because of the standard Pascal 'MOD' function. How do I get around that?

savage
20-04-2008, 06:17 PM
Which version of FPC are you using? I've not come across this error yet.

Christian Knudsen
21-04-2008, 05:47 AM
I'm using FPC 1.0.10 for Win32. The error message I'm getting when trying to compile is:

'Syntax error, "identifier" expected but "mod" found'

Some code excerpts:

VAR Event : TSDL_Event

{...}

WHILE SDL_PollEvent(@Event) <> 0 DO BEGIN
CASE Event.Type_ OF
SDL_KeyDown : BEGIN
CASE Event.Key.KeySym.Sym OF
SDLK_Up : KeyIsDown[KeyUp] := True;
SDLK_Down : KeyIsDown[KeyDown] := True;
SDLK_Right : KeyIsDown[KeyRight] := True;
SDLK_Left : KeyIsDown[KeyLeft] := True;
SDLK_Space : KeyIsDown[KeySpace] := True;
SDLK_Q : Stop := True;
SDLK_F12 : IF FullScreen THEN BEGIN
TheScreen := SDL_SetVideoMode(640, 400, 0, SDL_SWSURFACE);
FullScreen := False;
END
ELSE BEGIN
TheScreen := SDL_SetVideoMode(640, 400, 0, SDL_SWSURFACE OR SDL_FULLSCREEN);
FullScreen := True;
END;
END;
CASE Event.Key.KeySym.Mod OF
KMOD_Shift : WriteLineToScreenBuffer(1, 3, 0, 'SHIFT Pressed!');
END;
END;
SDL_KeyUp : BEGIN
CASE Event.Key.KeySym.Sym OF
SDLK_Up : KeyIsDown[KeyUp] := False;
SDLK_Down : KeyIsDown[KeyDown] := False;
SDLK_Right : KeyIsDown[KeyRight] := False;
SDLK_Left : KeyIsDown[KeyLeft] := False;
SDLK_Space : KeyIsDown[KeySpace] := False;
END;
END;
END;
END;

savage
21-04-2008, 06:50 AM
Yikes 1.0.10!! May I suggest you upgrade to 2.2.x from http://sourceforge.net/project/showfiles.php?group_id=2174
as this will mean most people who use FPC will be beter able to help out.

The 2.2.x compile is a much better compiler all round.

Christian Knudsen
21-04-2008, 10:06 AM
I actually have no clue as to why I'm using such an old version of FPC. I downloaded it through the freepascal.org site only a month ago. I guess I must have clicked a wrong link somewhere! :)

I'll install the new version and give it a go.

grudzio
21-04-2008, 04:09 PM
Are You sure it is Event.Key.KeySym.Mod not Event.Key.KeySym.Modifier?

Christian Knudsen
21-04-2008, 04:43 PM
Yeah, you're right. It's Modifier not Mod. I was thrown off by some C code using SDL. However, I've just discovered that I can also capture SHIFT by using SDLK_LSHIFT and SDLK_RSHIFT, which is a lot easier for my needs. Yay!

In other news, I've actually got the latest version of FPC installed. I misread the version of the IDE as the version of the compiler. :oops: