Recent

Author Topic: which unit is the getkeystate function in?  (Read 476 times)

nds

  • Newbie
  • Posts: 4
which unit is the getkeystate function in?
« on: January 24, 2020, 08:38:41 am »
under maсos please - in windows and so it works %)
lack of full help system is the main disadvantage of lazarus :'(

PascalDragon

  • Hero Member
  • *****
  • Posts: 958
  • Compiler Developer
Re: which unit is the getkeystate function in?
« Reply #1 on: January 24, 2020, 09:04:57 am »
GetKeyState is a Windows only function. Neither Lazarus nor FPC provide documentation for the API provided by the platform as that is handled by the OS providers (Microsoft with MSDN, Apple documentation, POSIX, etc.).

If you can't make use of existing cross platform functionality for your use case you'll need to research this for each platform separately. If you explain your needs the users here on the forum can likely help you find the right solution.

howardpc

  • Hero Member
  • *****
  • Posts: 3303
Re: which unit is the getkeystate function in?
« Reply #2 on: January 24, 2020, 09:15:18 am »
If you include
Code: Pascal  [Select]
  1. uses LCLIntf;
you get a widgetset implementation of GetKeyState.

I don't know how well it is implemented for the Mac, but it works fine on Linuxes.

nds

  • Newbie
  • Posts: 4
Re: which unit is the getkeystate function in?
« Reply #3 on: January 24, 2020, 09:34:38 am »
with
Code: Pascal  [Select]
  1. uses lclintf,lcltype;
builds but dont work with any virtual key exclude vk_shift

UPD: work in button.onclick and dont work in image.onclick :o

PascalDragon you know any crossplatform method to get key state?
« Last Edit: January 24, 2020, 10:10:05 am by nds »

Handoko

  • Hero Member
  • *****
  • Posts: 3345
  • My goal: build my own game engine using Lazarus

MarkMLl

  • Hero Member
  • *****
  • Posts: 615
Re: which unit is the getkeystate function in?
« Reply #5 on: January 24, 2020, 11:34:49 am »
GetKeyState is a Windows only function.

GetKeyState works on Linux too:
https://forum.lazarus.freepascal.org/index.php/topic,42439.msg297949.html#msg297949

It works but the results are somewhat platform-dependent. I was wrestling with shift keys a couple of weeks ago.

https://forum.lazarus.freepascal.org/index.php/topic,48110.msg345932.html#msg345932

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

trev

  • Sr. Member
  • ****
  • Posts: 398
  • Former Delphi 7 and Delphi 10.2 User
Re: which unit is the getkeystate function in?
« Reply #6 on: January 24, 2020, 12:37:45 pm »
o Lazarus v2.1.0 r62452, FPC v3.3.1 r42644, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

syntonica

  • Full Member
  • ***
  • Posts: 120
Re: which unit is the getkeystate function in?
« Reply #7 on: January 27, 2020, 08:05:41 am »
Unfortunately, the paradigm Windows uses is the polar opposite of what Cocoa uses. With Windows, you just override one method with a case statement that parses the message sent. With Cocoa, you need to subclass NSView.  The value you seek is a member of the NSEvent that is sent to the appropriate handler, whether mouse or keyboard related.

I haven't worked with the LCL yet, but the majority of this should be swept under the rug. I hope.  :-[