Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / IF ???=1 then

Author
Message
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 3rd Apr 2010 02:11
How can i make an IF that works when a specified key is pressed.
For example:

If "A"()=1 then...


I've tried with scancodes, but I dont understand how it works.
Someone know what should i do?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd Apr 2010 02:55
Something like:


I'm not a grumpy grandpa
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 3rd Apr 2010 03:10
Wee! It worked, thx!
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 3rd Apr 2010 03:46
And if i want it to work only when A is not pressed?
Levanthus
21
Years of Service
User Offline
Joined: 17th Apr 2003
Location: Cumbria, UK
Posted: 3rd Apr 2010 12:48 Edited at: 3rd Apr 2010 12:49
I'd preobably use

I tend to find if you use

it will only recognise the lower case a, so if you have caps on or hold shift etc it soesn't work

Windows 7 64 bit, AMD Phenom II x4 Black edition, 4 GB Ram, Radeon HD 4650, 540 GB HDD

I can see from your smile, you're not here for the sunset.
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd Apr 2010 13:35 Edited at: 3rd Apr 2010 13:51
Quote: "I'd preobably use "


Quote: "if keystate(30)=1 then...."



Quote: "I tend to find if you use "



Quote: "if inkey$()="a" then..."


Quote: "it will only recognise the lower case a, so if you have caps on or hold shift etc it soesn't work"



@Levanthus

I'm not quite sure what you're trying to demonstrate
if you want to be sure when pressing "a" key or "A" you can do it like:

if scancode()=30 then set cursor 50,50:print "Hi"


@Yitzu
If you want it works only if "a" orrrrrr "A" keys is not pressed:
if inkey$()>"a" then set cursor 5,5:print "Hi"

back to code.

I'm not a grumpy grandpa
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 3rd Apr 2010 15:06 Edited at: 4th Apr 2010 22:23
Another thing to remember:

If you are writing a program for yourself then ScanCode() is OK.

But if it's for use by other people, then remember that Inkey$() is the only method which will work with specific character keys on keyboards in all countries.

This is because Inkey$() responds to the keyboard character pressed (a, A etc) whereas ScanCode() responds to the physical key pressed and not all keyboards have the same thing on every key.

For example, on my Spanish QWERTY keyboard, (like UK and US keyboards), the ScanCode() code for the character a/A is 30.

In France however, using an AZERTY keyboard, if your program is polling for the A key you need to check for the ScanCode() value 16 - not 30. So if your program instructions say to press the A key but it is actually checking for the value 30 then you would be checking for the Q key.

There are also QWERTZ and other non-English keyboards (the majority of which I know you can disregard).

If the Inkey$() command needs to respond to a or A (ignoring the Caps Lock or Shift setting), simply use:

I$ = Upper$(Inkey$())
If I$="A" Then Do Something


or...

I$ = Lower$(Inkey$())
If I$="a" Then Do Something


TDK

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd Apr 2010 15:25
@TDK

Thanks for your explanation .

cheers.

I'm not a grumpy grandpa
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 4th Apr 2010 07:25
Wow, now i get it Ty thats very helpful, it will help a lot. THX!
GreenDixy
16
Years of Service
User Offline
Joined: 24th Jul 2008
Location: Toronto
Posted: 6th Apr 2010 06:11
This code will come in much use ty tdk (Sorry if this is bored jump)

s for movement
S for separate (AI)

f for flashlight
F for follow (AI)

======================================

Login to post a reply

Server time is: 2024-09-28 16:26:53
Your offset time is: 2024-09-28 16:26:53