Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 20th, 2012, 10:46 AM
steve53 steve53 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 4 steve53 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 39 sec
Reputation Power: 0
Enable arrow keys

I am working on a program that is basically finished, all but 2 tabstops are set to False so I can only tab between 2 TButtons. The issue that I have is when I press the space bar to operate 1 button the tabstops are set to 4 TRadioButtons that I want to tab between then pressing the space-bar again leaves to the next tabstop.

Someone sent me the following code to only allow the Tab and Space keys.

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
// Only allow tab & space keys to be forwarded to BetweenButton
if self.ActiveControl = BetweenButton then
if not (Key in [VK_TAB, VK_SPACE]) then
Key := 0;
end;

The following code is supposed to allow the arrow keys to be enabled but I cant seem to get them working.

procedure TForm1.DialogKey(var Msg: TWMKey);
begin
// Make sure the OnKeyDown handler is called for arrow keys
case Msg.CharCode of
VK_DOWN,
VK_UP,
VK_RIGHT,
VK_LEFT : if Assigned(onKeyDown) then onKeyDown(Self, Msg.CharCode, KeyDataToShiftState(Msg.KeyData));
else
inherited
end;
end;

Can someone please help me solve my problems.

Many thanks
Steve

Reply With Quote
  #2  
Old March 21st, 2012, 06:59 AM
Dimixx Dimixx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 68 Dimixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 53 m 47 sec
Reputation Power: 4
Hi,
First I couldn't exaclly understand the explanation of your program. Can you try explain it better especially the part when you press the space bar. Otherwise about the code you have been posted I tried this.
Code:
type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    { Private declarations }
    procedure DialogKey(var Msg: TWMKey); message CM_DIALOGKEY;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DialogKey(var Msg: TWMKey);
begin
  case Msg.CharCode of
    VK_DOWN, VK_UP, VK_RIGHT, VK_LEFT:
      if Assigned(onKeyDown) then
        onKeyDown(Self, Msg.CharCode, KeyDataToShiftState(Msg.KeyData));
    else
      inherited
  end;
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case Key of
    VK_DOWN: Top := Top + 5;
    VK_UP: Top := Top - 5;
    VK_LEFT: Left := Left - 5;
    VK_RIGHT: Left := Left + 5;
  end;
end;
end.
I found it here It works fine for me. So the DialogKey prccedure works fine. About your FormKeyDown procedure. With this
Code:
if not (Key in [VK_TAB, VK_SPACE]) then 
  Key := 0;
you accept only the tab or the spacebar key. So when you call this procedure from DialogKey with the pressing of the arrows you just skip them in the FormKeyDown procedure. Try to put them in the condition something like this
Code:
if not (Key in [VK_TAB, VK_SPACE, VK_DOWN, VK_UP, VK_RIGHT, VK_LEFT] ) then 
  Key := 0;
I think this sould be the way but again I didn't understand the hole idea of your program.

Dimiter.

Last edited by Dimixx : March 21st, 2012 at 07:02 AM.

Reply With Quote
  #3  
Old March 22nd, 2012, 05:52 AM
steve53 steve53 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 4 steve53 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 39 sec
Reputation Power: 0
Enable arrow keys

Thanks for your reply, I will try to explain better this time.

The form is as follows, the top of the form there are two TButtons, pressing the tab key allows one to move between the 2 and selected by pressing the spacebar. On pressing the spacebar the cursor drops below to 4 TRadioButtons that I need to select by using the tab key and executing by pressing the spacebar. From there the cursor drops again to a TDateTimePicker on the left allowing one to select a date from, tabbing to the TDateTimePicker on the right allowing one to select a date to. From there tabbing to a final TButton to calculate the date difference.

Everything is working as expected, but for the 4 TRadioButtons, the 2 top TButtons, the 2 TDateTimePickers and the Calculate TButton can all be moved to by using the tab key and selected by pressing the spacebar, but I cannot move between the 4 TRadioButtons. I hope this explains the form layout and what I am trying to accomplice.

As I am a new user I cannot put a link here, but if you are kind enough to email me then I would send you the link to show you an avi explaining in full.

kindest regards
Steve

Reply With Quote
  #4  
Old March 22nd, 2012, 05:56 AM
steve53 steve53 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 4 steve53 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 39 sec
Reputation Power: 0
Enable arrow keys

Sorry, just realised a mistake, it should be as follows;

The form is as follows, the top of the form there are two TButtons, pressing the tab key allows one to move between the 2 and selecting by pressing the spacebar. On pressing the spacebar the cursor drops below to 4 TRadioButtons that I need to select by using the arrow keys and once selected pressing the spacebar makes it jump to the next section. From there the cursor drops again to a TDateTimePicker on the left allowing one to select a date from, tabbing to the TDateTimePicker on the right allowing one to select a date to. From there tabbing to a final TButton to calculate the date difference.

Everything is working as expected, but for the 4 TRadioButtons, the 2 top TButtons, the 2 TDateTimePickers and the Calculate TButton can all be moved to by using the tab key and selected by pressing the spacebar, but I cannot move between the 4 TRadioButtons. I hope this explains the form layout and what I am trying to accomplice.

As I am a new user to this forum I cannot put a link here, but if you are kind enough to email me then I would send you the link to show you an avi explaining in full.

kindest regards
Steve

P.S. The reason for the way I want it to work is that I am designing it for a blind user.

Reply With Quote
  #5  
Old March 22nd, 2012, 12:32 PM
Dimixx Dimixx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 68 Dimixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 53 m 47 sec
Reputation Power: 4
Hi,
First may be because you're new in the forum you don't know there is a Edit post button there is no need to repost
Now about the project now your idea is a lot clearer. So are you using 4 TRadioButtons? If so try with TRadioGroup. In the Items property you can add as many radiobuttons that you want. There you can navigate through the radiobuttons with the arrows without any code.

Dimiter

Last edited by Dimixx : March 22nd, 2012 at 01:37 PM.

Reply With Quote
  #6  
Old March 22nd, 2012, 02:54 PM
steve53 steve53 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 4 steve53 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 39 sec
Reputation Power: 0
Hi Dimiter, Thanks you for your reply, yes I now know I can edit posts, but I only realised after I resubmitted it, sorry.

I tried a TRadioGroup and still cannot move using the arrow keys, I suppose because I have the following code so only the Tab key and Spacebar is used, ie;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
// Only allow tab & space keys to be forwarded to BetweenButton
if self.ActiveControl = BetweenButton then
if not (Key in [VK_TAB, VK_SPACE] ) then
Key := 0;
end;

I would have to somehow make the arrow keys enabled again while only using the Radio Buttons

Regards
Steve

Reply With Quote
  #7  
Old March 22nd, 2012, 04:09 PM
Dimixx Dimixx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 68 Dimixx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 53 m 47 sec
Reputation Power: 4
Thumbs down

Hi,
I think you're right. You will have to think some kind of logic about when you are in the radiogroup, so you will have to accept only the arrows and all other cases when you will accept only enter and space bar. Although I have a problem setting the focus on the radiogroup. If a switch it wirh Tab it's ok arrows work, but if I try to make it with code like this radiogroup.SetFocus you can't work with the arrows. So I came up with another idea don't switch the focus on the radiobuttons after pressing the first button with space bar just set some boolean varaible to true and check it in the DialogKey method then on the FormKeyDown make it something like that
Code:
case Key of 
VK_DOWN: RadioGroup1.ItemIndex := RadioGroup1.ItemIndex - 1; 
VK_UP: RadioGroup1.ItemIndex := RadioGroup1.ItemIndex + 1;  
end;

Try both ways and see which you find better


Dimiter

Reply With Quote
  #8  
Old March 22nd, 2012, 04:59 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
I seem to be missing something.
What is BetweenButton?

The code already restricts the special action to when this object has focus,
so I am not sure why it affects the TRadioGroup or any other components.

What happens if you remove the DialogKey code?

Reply With Quote
  #9  
Old May 30th, 2012, 10:12 AM
fizagul44 fizagul44 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 3 fizagul44 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 53 sec
Reputation Power: 0
Delphi Programming forum discussing Delphi related topics including Kylix

Delphi Programming forum discussing Delphi related topics including Kylix very nice frnd thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Enable arrow keys

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap