Recent

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

nds

  • New member
  • *
  • Posts: 8
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: 5446
  • 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: 4144
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

  • New member
  • *
  • Posts: 8
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: 5129
  • My goal: build my own game engine using Lazarus

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: which unit is the getkeystate function in?
« Reply #6 on: January 24, 2020, 12:37:45 pm »

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.  :-[

 

TinyPortal © 2005-2018