Page 1 of 1
Checking for key presses
Posted: Fri Mar 16, 2012 7:56 pm
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
Re: Checking for key presses
Posted: Fri Mar 16, 2012 9:55 pm
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
Re: Checking for key presses
Posted: Fri Mar 16, 2012 10:08 pm
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.
Re: Checking for key presses
Posted: Tue Mar 20, 2012 12:13 pm
by Shardik
In idle's code example Procedure has to be changed to Procedure
C.
Otherwise you will receive the following error on pressing a key:
PB IDE wrote:Line: 6 - Invalid memory access