Recent

Author Topic: OnKeyDown not in my events  (Read 2328 times)

entrisity

  • New Member
  • *
  • Posts: 12
OnKeyDown not in my events
« on: October 23, 2018, 10:03:41 pm »
Hey!

I want to have a OnKeyDown event on a image that im using but its not there. Not too sure if that needs a package or why its not showing up.

Thanks in advance!

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: OnKeyDown not in my events
« Reply #1 on: October 23, 2018, 10:10:43 pm »
TImage is a TGraphicControl, which does not have a window handle like TWinControls do.
It cannot receive focus or key events. Only an image's TWinControl Parent can respond to OnKeyDown etc.

entrisity

  • New Member
  • *
  • Posts: 12
Re: OnKeyDown not in my events
« Reply #2 on: October 23, 2018, 10:29:24 pm »
oh shit didn't know that. Thanks for the quick response! I really appreciate it :D

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: OnKeyDown not in my events
« Reply #3 on: October 23, 2018, 11:50:47 pm »
Do note that you can always embed your TImage into a container control that has an OnKeyDown event, like TScrollBox, TPanel, etc.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: OnKeyDown not in my events
« Reply #4 on: October 24, 2018, 02:36:24 am »
The key events are not published for the TPanel and such would need to be setup in code for runtime.

 Also, I believe a property needs to altered to allow it to accept keys
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: OnKeyDown not in my events
« Reply #5 on: October 24, 2018, 03:11:34 am »
The key events are not published for the TPanel and such would need to be setup in code for runtime.

 Also, I believe a property needs to altered to allow it to accept keys

Yes, you're right. I was just pointing out a solution: embeding the image in any container control which descends from TWinControl. It's easier, of course, if it has the OnKeyXXX events published  :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: OnKeyDown not in my events
« Reply #6 on: October 24, 2018, 03:15:33 am »
A TImage cannot exist without a form and a TForm has got an OnKeyDown event...
I'm just curious... why do you need this ???
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: OnKeyDown not in my events
« Reply #7 on: October 24, 2018, 04:06:39 pm »
With TWincontrols of if you don't set the TabStop then it won't receive any keyboard items..

 
 Create the events you need for the key events manually and set them during startup time like in the
FormCreate event etc..

  Personally I think this is stupid but I guess you can also call the SetFocus on the control during a Mouse Click..
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018