Recent

Author Topic: [SOLVED] Keycodes on non-Windows systems  (Read 4623 times)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
[SOLVED] Keycodes on non-Windows systems
« on: September 15, 2012, 09:56:53 am »
For the SQLDB tutorial I was working on, chris_c gave a helpful hint. He ssuggested using a keyup event handler and catching the delete key, then use that to delete data from a dbgrid.

I got it working on Windows:
Code: [Select]
uses... LCLType
....
procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState
  );
begin
  // Check for del key being hit and delete the current record in response
  if key=VK_DELETE then
  begin
    // database stuff here
  end;
end;

I vaguely remember though that lcltype is Windows only and one should use another unit for cross-platform compatibility... Am I right? If so, which one ;) and where on the wiki is this documented?

If I'm wrong... well, it's been known to happen before ;)

Thanks
« Last Edit: September 15, 2012, 11:10:24 am by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Keycodes on non-Windows systems
« Reply #1 on: September 15, 2012, 10:33:45 am »
On linux the delete key produces a keyup key of 46 which is the same value as VK_DELETE but it doesnt seem to be defined...

obviously we can't rely on the value 46 .....
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Keycodes on non-Windows systems
« Reply #2 on: September 15, 2012, 10:41:26 am »
Quote
I vaguely remember though that lcltype is Windows only and one should use another unit for cross-platform compatibility... Am I right? If so, which one  and where on the wiki is this documented?
No, LCLType, LCLIntf and LCLProc is defined with Windows compatibility in mind, but everything there works on all platforms.

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Keycodes on non-Windows systems
« Reply #3 on: September 15, 2012, 10:46:00 am »
yeah just found LCLType myself after a bit of digging

VK_DELETE does work on Linux! (even if it is a windows key code - but then Delphi did have its roots firmly in windows...)
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Keycodes on non-Windows systems
« Reply #4 on: September 15, 2012, 11:10:08 am »
Thanks, Leledumbo & Chris (for adding the keycode info to the LCL Key Handling wiki page) ;)

That nicely fits with my motto: "If it's not the wiki, it's not documented[1]"
[1] Of course, unless it is in the LCL.CHM and FPC pdfs/chms, but well... I'd rather edit the wiki. Much quicker and easier.

I added a link to LCL Key Handling in the Multiplatform Programming Guide...
« Last Edit: September 15, 2012, 11:16:01 am by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: [SOLVED] Keycodes on non-Windows systems
« Reply #5 on: September 15, 2012, 11:30:15 am »
damn i was busted  ;D I can't claim it was in the wiki all along now!
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: [SOLVED] Keycodes on non-Windows systems
« Reply #6 on: September 15, 2012, 11:46:08 am »
;)

Actually found that wiki page before asking the question... so I was very interested when I saw your name come by on the recently changed wiki page ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018