Recent

Author Topic: MauseAndKeyInput  (Read 1780 times)

RastaManKing

  • New Member
  • *
  • Posts: 17
MauseAndKeyInput
« on: March 31, 2024, 09:53:36 am »
hello!
im back to programming from a long rest and im having trouble in a routine,
maybe someone can give me a tip on how to achieve my goal.

i have a program that executes a procedure inside a TThread.ExecuteInThread(myProcedure);

the problem is that in myProcedure i have a KeyInput.Press(VK_SPACE); which brings up CheckSynchronize break in gtk2widgetset.inc

i tried setting up a boolean flag, and instead of executing KeyInput in threat, i change boolean flag,
then have a repeat..until infinite loop just monitoring the boolean flag and pressing space, but this locks my main form.. which brings me back to main problem..

any ideas how to achieve a key press from a background thread???  :(

Thaddy

  • Hero Member
  • *****
  • Posts: 14376
  • Sensorship about opinions does not belong here.
Re: MauseAndKeyInput
« Reply #1 on: March 31, 2024, 11:48:08 am »
This interfears with the main thread messageloop. It can probably be done, but with some hacks. The messageloop is started in application.dorun, but that is private I believe.
On windows you need no hacks and you can use the SetWindowsHookEx api which can work with a thread.
« Last Edit: March 31, 2024, 12:14:44 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

RastaManKing

  • New Member
  • *
  • Posts: 17
Re: MauseAndKeyInput
« Reply #2 on: March 31, 2024, 10:25:59 pm »
i should of specified, i am using linux.. any ideas on the type of hack that needs to be done for this? point me in the right direction??

alpine

  • Hero Member
  • *****
  • Posts: 1064
Re: MauseAndKeyInput
« Reply #3 on: April 01, 2024, 01:13:55 am »
Put KeyInput.Press(VK_SPACE) in a separate method PressSpace and call instead
Code: Pascal  [Select][+][-]
  1.   TThread.Synchronize(TThread.CurrentThread, @PressSpace);
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

RastaManKing

  • New Member
  • *
  • Posts: 17
Re: MauseAndKeyInput
« Reply #4 on: April 01, 2024, 05:57:36 am »
Put KeyInput.Press(VK_SPACE) in a separate method PressSpace and call instead
Code: Pascal  [Select][+][-]
  1.   TThread.Synchronize(TThread.CurrentThread, @PressSpace);

This worked perfect!
answer short and to the point,
thanks for sharing knowledge!

alpine

  • Hero Member
  • *****
  • Posts: 1064
Re: MauseAndKeyInput
« Reply #5 on: April 01, 2024, 10:45:03 am »
This worked perfect!
answer short and to the point,
thanks for sharing knowledge!
No problem.

Perhaps you should consider another way for doing this. Is the additional thread really needed?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

 

TinyPortal © 2005-2018