IonicWind Software

IWBasic => General Questions => Topic started by: LarryMc on March 03, 2010, 02:16:01 PM

Title: Keyboard Input
Post by: LarryMc on March 03, 2010, 02:16:01 PM
In the designer I'm working on I'm using the arrow keys to move a control around.

I want to implement a coarse adjustment by using CTRL+ the arrow keys.

I haven't been able to figure out where and how to trap that.

?

LarryMc
Title: Re: Keyboard Input
Post by: fasecero on March 03, 2010, 06:31:50 PM
Hi Larry, this work for me, I don't know if is the better approach  :)


DECLARE IMPORT, _GetAsyncKeyState ALIAS GetAsyncKeyState(vKey AS INT),WORD

DIALOG w1
OPENWINDOW w1,0,0,300,202,0x80C80080,0,"Caption",&w1_handler

run = 1
WAITUNTIL run=0

SUB w1_handler
SELECT @MESSAGE
CASE @IDKEYDOWN
ProcessKeyboard(@wparam)
CASE @IDCREATE
CENTERWINDOW w1
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
run = 0
CLOSEDIALOG w1,@IDOK
ENDSELECT
RETURN
ENDSUB

SUB ProcessKeyboard(int nKey)
IF _GetAsyncKeyState(17)>0 THEN ' if control is pressed
if nKey = 37 THEN
DEBUGPRINT "left"
ENDIF
if nKey = 38 THEN
DEBUGPRINT "top"
ENDIF
if nKey = 39 THEN
DEBUGPRINT "right"
ENDIF
if nKey = 40 THEN
DEBUGPRINT "bottom"
ENDIF
ENDIF
ENDSUB
Title: Re: Keyboard Input
Post by: LarryMc on March 03, 2010, 07:23:36 PM
fasecero
Your code got me over the hump.

I modified it to do exactly what i wanted as follows:
SUB ProcessKeyboard(int nKey)
int cx=0,cy=0,adj=0
IF _GetAsyncKeyState(17)>0 THEN ' if control is pressed
adj=3
else
adj=0
endif
if nKey = 37 THEN
'DEBUGPRINT "left"
cx=-1-adj
ENDIF
if nKey = 38 THEN
'DEBUGPRINT "top"
cy=-1-adj
ENDIF
if nKey = 39 THEN
'DEBUGPRINT "right"
cx=1+adj
ENDIF
if nKey = 40 THEN
'DEBUGPRINT "bottom"
cy=1+adj
ENDIF
if cx or cy
MoveCtrls(cx,cy)
endif
ENDSUB


Thanks again

LarryMc