POKE

From QB64 Wiki
Revision as of 01:54, 7 October 2009 by 90.231.62.232 (talk)
Jump to navigation Jump to search

POKE sets the value of a specified memory address, POKE can only be used to set a value from 0 to 255 (a byte).


Syntax: POKE address, bytevalue


  • A segment should be defined using DEF SEG, if you don't define a segment qbasics ordinary segment will be used.
  • POKE sends byte values to memory areas. It does not directly access the registers.
  • DEF SEG alone should always be used when access to that memory is no longer necessary.
  • POKE is safer to use than OUT which could damage a PC register.


Example: Turning keyboard Lock and Insert modes on and off.

POKE 1047,PEEK(1047) OR 16 ' ENABLES SCROLL LOCK
POKE 1047,PEEK(1047) OR 32 ' ENABLES NUMBER LOCK
POKE 1047,PEEK(1047) OR 64 ' ENABLES CAPS LOCK
POKE 1047,PEEK(1047) OR 128 ' ENABLES INSERT MODE
Note: Use XOR instead of OR above to alternate between on and off modes.
POKE 1047,PEEK(1047) AND 239 ' TURNS OFF SCROLL LOCK (239 = 255 - 16)
POKE 1047,PEEK(1047) AND 223 ' TURNS OFF NUMBER LOCK (223 = 255 - 32)
POKE 1047,PEEK(1047) AND 191 ' TURNS OFF CAPS LOCK (191 = 255 - 64)
POKE 1047,PEEK(1047) AND 127 ' TURNS OFF INSERT MODE (127 = 255 - 128)
Note: Using AND requires that the bit value is subtracted from 255 to turn off a bit.
Warning: The keyboard lights may NOT change so it is a good idea to restore the original settings!



See also: PEEK, OUT, VARSEG, VARPTR, Scancodes(demo)


Navigation:

Go to Keyword Reference - Alphabetical

Go to Keyword Reference - By usage