Checking for key presses

Linux specific forum
JustinJack
User
User
Posts: 89
Joined: Thu Feb 04, 2010 7:34 am
Location: Decatur, TX
Contact:

Checking for key presses

Post by JustinJack »

Hello everyone, can someone please get me an example of how to do the following in PB for Linux?

Code: Select all

Repeat
    Delay(100)
Until (GetAsyncKeyState_(#VK_ESCAPE) & 32768)  = 32768 
End 1
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Checking for key presses

Post by idle »

try this and see here
http://developer.gnome.org/gtk-tutorial/2.22/x182.html

Code: Select all


Global gkey 

Procedure KeyPressedCallback(*widget,*event.GdkEventKey,*udata );
  gkey =  *event\keyval & $FF
  Debug PeekS(*event\string) + " " + Str(gkey)
EndProcedure   

OpenWindow(0,0,0,200,100,"keyPress")
g_signal_connect_(WindowID(0),"key_press_event",@KeyPressedCallback(),0);

Repeat 
  ev = WaitWindowEvent()
  
Until gkey = #PB_Key_Escape   
Windows 11, Manjaro, Raspberry Pi OS
Image
JustinJack
User
User
Posts: 89
Joined: Thu Feb 04, 2010 7:34 am
Location: Decatur, TX
Contact:

Re: Checking for key presses

Post by JustinJack »

The only thing is I'm trying to do it without opening a window. Console or otherwise. Actually, It's only curiosity now. I am writing a server application for linux (my first linux app) and I was trying to decide how I was going to signal it to start, stop, or restart. What I decided to do is to have the program listen on two ports, one for internet clients and data, and one for localhost, so IT people can start it and stop it from bash. If they run the program with certain parameters, it will just send itself a command locally. I'm sure there are other ways to do it, but I don't know them yet.
User avatar
Shardik
Addict
Addict
Posts: 2067
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Checking for key presses

Post by Shardik »

In idle's code example Procedure has to be changed to ProcedureC.
Otherwise you will receive the following error on pressing a key:
PB IDE wrote:Line: 6 - Invalid memory access
Post Reply